将jQuery函数更改为页面加载

时间:2010-12-03 19:42:34

标签: javascript jquery

任何人都可以告诉我如何将当前由单选按钮控制的以下语句更改为文档加载函数。

基本上我希望幻灯片div在页面加载时从左向右滑出。 jQuery的:

jQuery(function() { 
jQuery('#slide').hide(); 
jQuery(':radio[name=radiobutton]').click(function() { 
    var value = $(this).val(); 
    if (value === 'Y') { 
        jQuery('#slide').show('slow'); 
    } else if (value === 'N') { 
        jQuery('#slide').hide('slow'); 
    } 
}); 

HTML:

<div id="slide" class="alpha60">

<p class="statement_style_head">Content goes here</p>

<p class="statement_style_text">A line or two of text goes here </p>

</div>

3 个答案:

答案 0 :(得分:0)

$(document).ready({。你的员工。});

答案 1 :(得分:0)

一种方法是在加载时点击它,如$('input[name=radiobutton]').click();$('input[name=radiobutton]').trigger('click');

另一种方法是将代码放在函数中并在加载时调用该函数。

function showSomething(){
   // code here
}

showSomething();

答案 2 :(得分:0)

Document.ready是javascript的onload,它等待一切准备就绪然后执行...你的代码,安全和onload的最佳实践

$(document).ready(function() {
    $("divid").animate({top:'10px', bottom:0}, 3000);
    });