jquery事件冒泡
有人可以向我解释为什么
var divdbl = $("div:first");
var i = 0;
divdbl.change(function(){
alert('change');
}).click();
divdbl.click(function(){
i++;
alert('click '+i);
}).change();
他们的行为就像他们在称呼自己一样,即使我这样做
divdbl.click(function(){
i++;
alert('click '+i);
}).change();
divdbl.change(function(){
alert('change');
}).click();
,就好像他们在称呼自己而不是对方。
编辑
var divdbl = $("div:first");
var i = 0;
divdbl.change(function(){
alert('change');
});
divdbl.click(function(){
i++;
alert('click '+i);
}).change().click();
我刚刚意识到我想要完成的是强制它们在加载时运行一次 上面的代码有意义吗?
Can someone explain to me why
var divdbl = $("div:first");
var i = 0;
divdbl.change(function(){
alert('change');
}).click();
divdbl.click(function(){
i++;
alert('click '+i);
}).change();
behaves like they are calling themselves, even if I do it like this
divdbl.click(function(){
i++;
alert('click '+i);
}).change();
divdbl.change(function(){
alert('change');
}).click();
its as if they are calling themselves instead of the other.
EDIT
var divdbl = $("div:first");
var i = 0;
divdbl.change(function(){
alert('change');
});
divdbl.click(function(){
i++;
alert('click '+i);
}).change().click();
i just realized that what i wanted to accomplish was to force them to run once on load
Would the above code make sense?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,首先,存在一个问题,因为您在定义之前调用触发
change()
处理程序。你想实现什么目标?调用.change()
和.click()
运行这些事件的函数。编辑:
根据您最近对问题的更新:是的,这将按预期工作。 .click 和 .change 都会在加载时调用。
Well, first of all, there's an issue because you are calling triggering
change()
handler before it is defined. What are you trying to accomplish? Calling.change()
and.click()
runs the functions for those events.EDIT:
Based on your recent update to your question: Yes, that will work as intended. Both .click and .change will be invoked upon load.