是因为这些动态加载的这些HTML页面,是在列表数据页面的HTML元素,css,js代码加载完后,再添加的HTML元素,
在浏览器解析到静态的页面元素时, 解析到js的这些绑定标签事件的js代码(上面的JS代码)的时候,这些绑定事件的标签元素还没有生成,
(因为js代码加载完后,才会有这些绑定事件的标签),所以这些JS 代码的绑定的事件,根本就没有绑定到这些动态加载的标签上,所以哪些事件不会触发。
简单来说,就是js初始化时,没有找到指定的html元素,绑定失败
解决方案:
使用delegate()函数
语法:$(selector).delegate(childSelector,event,data,function)
例子:
// 单击表格某一行选中radio按钮
$("#video").delegate("tr","click", function(){
// alert("66666");
// 下面为原来的js
// $("#video tr").click(function(){
/*当单击表格行时,把单选按钮设为选中状态*/
$(this).find("input[type='radio']").prop("checked",true);
/*$(this).find("input[type='checkbox']").change();*/
if(event.target.type != 'checkbox')
{
/*当单击表格行时,把复选框设为选中状态*/
if($(this).find("input[type='checkbox']").prop("checked")){
$(this).find("input[type='checkbox']").attr("checked",false);
}else{
$(this).find("input[type='checkbox']").attr("checked",true);
}
$(this).find("input[type='checkbox']").trigger('change'); // 触发change事件
}
});
<table id="video" border="0" cellspacing="1" cellpadding="0"
class="table table-base table-hover">
<thead>
<tr>
<th width="40">
<!-- <input type="checkbox"> --> 选择
</th>
<th width="50">序号</th>
<th>型号</th>
<th>通道号</th>
<th>IP地址</th>
<th>别名</th>
<th>端口号</th>
<th>协议类型</th>
<th>经度</th>
<th>纬度</th>
<th>接入时间</th>
<th>分组</th>
<th>地址码</th>
<th width="100">状态</th>
<th width="100">操作</th>
</tr>
</thead>
<tbody id="videoTbody"></tbody>
</table>