【发布时间】:2011-07-21 18:30:49
【问题描述】:
在里面创建函数是否正确
$(document).ready(function() {
像这样:
$(document).ready(function() {
function callMe() {
}
});
.ready() 内部的函数不必在 DOM 准备好并触发ready() 内部的事件之前调用。
只是为了澄清一点 - 这是说明问题的代码:
$(function() {
var ind = 0;
// some event is executed and changes the value of the ind
// another event which affects the ind variable
// and another one - after this event we call our function
// there's another event - and we call our function again
我需要调用的函数需要 ind 变量的更新值 - 我想我可以将其作为参数传递,但有更好的方法吗?
另外 - 另一个重要的事情是,有问题的 function() 也可以更改 ind 变量的值 - 例如递增它 (ind++)。
【问题讨论】:
标签: jquery document document-ready