jQuery:绑定负载+同时更改 [英] Jquery: bind load + change simultaneously
本文介绍了jQuery:绑定负载+同时更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在许多情况下,我需要在加载后将行为绑定到元素,然后在事件触发后将其绑定到元素(例如"change"). 我认为最好的方法是使它处于同一行:
In many cases, I need to bind a behaviour to an element after loading, and then after an event triggering (like "change"). I think the best way would be to make it in the same line:
$('#element_id').bind('load, change', function () {
...
});
但这仅适用于更改",不适用于负载".有更好的方法吗?
But this works only for "change" and not for "load". There is a better way?
推荐答案
我偶然发现了同一问题.删除逗号是不够的,至少在这种情况下还不够:
I stumbled across the same problem. Removing comma is not enough, at least not in this case:
$(document).ready(function(){
$('#element_id').bind('load change', function () {
... // (this DOESN'T get called on page load)
});
});
我想load
事件是在$(document).ready()
之前触发的.
I guess load
events get triggered before $(document).ready()
.
这是一个简单的解决方案:
This is a simple solution:
$(document).ready(function(){
$('#element_id').bind('change', function () {
...
});
$('#element_id').trigger('change');
});
这篇关于jQuery:绑定负载+同时更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文