[英]Events javascript does not work after loading content into div with Ajax.
I have a table on my site, whenever you click on the first checkbox, all others are selected and are also performed other actions that does not matter. 我的网站上有一张表格,每当您单击第一个复选框时,都会选中所有其他复选框,并且还会执行其他无关紧要的操作。 Once the site opens, these data are loaded directly on the page with PHP. 网站打开后,这些数据将直接使用PHP加载到页面上。
http://i.imgur.com/GRIFbzN.png http://i.imgur.com/GRIFbzN.png
Just above, I have a 'select' field with some options, whenever you change the option, you made an ajax request that returns other data, but with the same structure in HTML with the same checkbox and others like elements. 就在上面,我有一个带有某些选项的'select'字段,每当您更改选项时,您都会发出一个ajax请求,该请求返回其他数据,但在HTML中具有相同的结构,具有相同的复选框以及其他类似元素的元素。 This data is loaded into the table, but after loading the javascript events does not work anymore. 此数据已加载到表中,但是加载javascript事件后不再起作用。 How to solve this? 如何解决呢?
HTML: http://pastebin.com/jU5nZURs HTML: http : //pastebin.com/jU5nZURs
Javascript: http://pastebin.com/XT1ty019 Javascript: http : //pastebin.com/XT1ty019
Thanks! 谢谢!
Events are bound to existing DOM nodes. 事件绑定到现有的DOM节点。
When you replace / remove the nodes, the events bound to them go away, too. 当您替换/删除节点时,绑定到它们的事件也会消失。
You need to run this again after you load new content: 加载新内容后,您需要再次运行此命令:
$(".checkData").on( "click", countChecked );
$("#checkAll").click(function(){
$('input:checkbox').not(this).prop('checked', this.checked);
countChecked();
});
ps ps
Put it in a function so you don't duplicate code. 将其放在函数中,这样就不会重复代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.