开发者

How to set button as default selected class (jquery selectable)

开发者 https://www.devze.com 2023-02-27 02:00 出处:网络
Hey there, total javascript noob here. Just wondering, I\'ve set up some buttons inside ul tags using jquery selectable, which change colour when I click on them. One problem though, how do I make one

Hey there, total javascript noob here. Just wondering, I've set up some buttons inside ul tags using jquery selectable, which change colour when I click on them. One problem though, how do I make one of them select on the load of the page?

Thanks!

edit: here's my code:

    <link rel="stylesheet" href="style/style.css" media="screen,projection" type="text/css" />
  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="https://ajax.googleapis.com/aja开发者_JAVA百科x/libs/jquery/1.5.2/jquery.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript">

$(document).ready(function(){
    setLink('single');
    $('#target').load($('#single a:first').attr('href'));
});

function setLink(id){
    $('#'+id+' a').click(function(e){
        $('#target').load(
            this.href,
            function(){
                setLink('target');
            }
        );
        return false;
    });
}

</script>
<style type="text/css">
#selectable .ui-selecting {
    background-image:url(../images/nav-li-bcg.png);
}
#selectable .ui-selected {
    background-image:url(../images/nav-li-bcg.png);
}
</style>

  <script>
  $(document).ready(function() {
    $("#selectable").selectable();
    $document.getElementById('current1').click();
  });
  </script>
</head>
<body>
<div id="tabs">
<div id="navigation">
<div id="single">
<div class="anchor1">
<ul id="selectable">
<li class="current1" id="current1"><a href="form1.php"><span>1</span></a></li>
<li><a href="form2.php"><span>2</span></a></li>
<li><a href="form3.php"><span>3</span></a></li></ul>
</div>
<div class="clear"></div></div></div><!-- navigation -->
<div class="info">
<div class="top"></div>
<div id="target">
</div>


Simulate a click on document ready?

$(document).ready(function() {
    $(".selectable .buttonSelector:first").click();
});


$('#myListItem').addClass('ui-selected');
0

精彩评论

暂无评论...
验证码 换一张
取 消