Jquery在页面加载时启动切换的最佳方法

时间:2011-10-07 19:31:38

标签: jquery

所以我设置了一些带有切换功能的div,我希望第一个在页面加载时切换为可见,这是最好的方法吗?感谢

$('.paneltop').click( function(){
    $(this).next('div').animate(
    {'height':"toggle"});
    $(this).toggleClass('openpane')     

1 个答案:

答案 0 :(得分:1)

您可以将jQuery.toggle.ready()一起使用。 它应该是这样的:

$(document).ready(function(){
  $(".paneltop").next("div").toggle();
});

注意:如果您希望它打开,可以使用.show()代替.toggle()

jQuery.toggle - http://api.jquery.com/toggle/