在内部创建函数是否正确
$(document).ready(function() {
如下所示:
$(document).ready(function() {
function callMe() {
}
});
在DOM准备就绪并触发ready()
内的事件之前,不必调用.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++
)。
https://stackoverflow.com/questions/6780890
复制相似问题