jquery .on()只能运行一次 [英] jquery .on() only works once
本文介绍了jquery .on()只能运行一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含多个复选框输入的表格:
I have a table with multiple checkbox inputs:
<form>
<table id="table">
<tr>
<td><input type="checkbox" value="1" class="someClass"></td>
<td><input type="checkbox" value="1" class="someClass"></td>...
当选中/取消选中该框时,某些jquery会从另一个文件刷新表格:
And some jquery that refreshes the table from another file when the box is checked/unchecked:
$(".someClass").on("change", function() {
$('#edit').ajaxSubmit(); //Submitting the form with id "edit"
$("#table").load("tablerefresh");
});
我的问题是当我选中/取消选中一个方框时,表格只会刷新一次,而且我应该每次检查/取消选中该框时都这样做,我到处寻找并且似乎无法找到解决方案。有什么想法?
My problem is that when I check/uncheck a box, the table will refresh only once, and it should do it every time I check/uncheck the box, I've looked everywhere and can't seem to find a solution. Any ideas?
推荐答案
这可能是委托问题,因为 #table
不会更改,将其用作范围,定位 .someClass
inside:
This is probably a matter of delegation, since #table
doesn't change, use it as the scope, targeting .someClass
inside:
$("#table").on("change", ".someClass", function() {
$('#edit').ajaxSubmit(); //Submitting the form with id "edit"
$("#table").load("tablerefresh");
});
注:
您也可以使用 delegate()
:
$("#table").delegate(".someClass", "change", function(){
//Code
});
这篇关于jquery .on()只能运行一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文