[英]DOM not fully loaded?
When using jQuery document ready, ie $(document).ready(function() { }
is there any chance that the DOM has not fully loaded yet? 当使用jQuery文档时,即
$(document).ready(function() { }
是否有可能DOM尚未完全加载?
I am using some 3 rd party tools (Telerik's grid) and have set a client template to display a checkbox instead, just like this . 我使用一些第三方工具(Telerik的网格),并建立一个客户端模板来显示一个复选框来代替,就像这样 。 Code:
码:
.ClientTemplate("<input type='checkbox' name='checkedRecords' value='<#= OrderID #>' />")
The reason I ask is that I am attempting to hook up an event to all checkboxes to monitor change
: 我问的原因是我试图将事件连接到所有复选框以监视
change
:
$(':input').change(
function () {
alert('you fired!');
});
I put a checkbox manually outside of the Telerik grid code, and it hooks up to the checkbox changing, but none of the checkboxes inside the telerik grid do... 我在Telerik网格代码之外手动设置了一个复选框,它连接到复选框更改,但telerik网格内的复选框都没有...
And in that case - is there a work around? 在那种情况下 - 是否有解决方法?
There's no chance that the statically defined DOM in the HTML page is not loaded yet at $(document).ready()
. HTML页面中静态定义的DOM不可能在
$(document).ready()
加载。 But, if you're using a third party library that is dynamically loading or creating HTML, there is no guarantee that the library has done it's business at the time of $(document).ready()
. 但是,如果您正在使用动态加载或创建HTML的第三方库,则无法保证库在
$(document).ready()
时已经完成了它的业务。 In fact, it's very likely that is has not. 事实上,它很可能没有。
You have a couple options: 你有几个选择:
.live()
capabilities in jQuery to capture events for even DOM objects that don't exist yet at the time you specify that you want to hook up to them. .live()
功能捕获甚至在您指定要连接它们.live()
不存在的DOM对象的事件。 You can read about .live()
here: http://api.jquery.com/live/ . .live()
: http : //api.jquery.com/live/ 。 It works mostly like a normal event handler except that it only works for some events and there are some differences in how you might stop propogation.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.