【发布时间】:2013-11-09 23:28:57
【问题描述】:
我不确定我们何时使用 $(document).ready(function() { }); 以及何时可以声明 $(function() { } 而无需在 $(document).ready(function() { }); 中声明
例如下面的sn-p:
<body>
<textarea id="test" cols="50" rows="15"><p><h3>Test H3</h3>This is some sample text to test out the <b>WYSIWYG Control</b>.</p></textarea>
<script type="text/javascript">
$(function() {
$("textarea").htmlarea();
});
</script>
在不使用$(document).ready(function() { }); 的情况下工作,但如下:
<body>
<textarea id="test" cols="50" rows="15"><p><h3>Test H3</h3>This is some sample text to test out the <b>WYSIWYG Control</b>.</p></textarea>
<script type="text/javascript">
$(document).ready(function(){
$("btn").click(function(){
alert('Hello!!!');
});
});
$(function() {
$("textarea").htmlarea();
});
</script>
当我按下带有id="btn" 的按钮时,它什么也不做。
我做错了吗?
【问题讨论】:
标签: jquery