[英]Is it possible to rebind jquery events after the DOM has changed by an ajax call?
我有一个由ajax调用动态重新填充的表。
我还有一个keyup事件,它根据用户输入过滤表行:
$('input#DocumentType').keyup(function () { filter rows });
但是当我从ajax调用中重新填充表时。 过滤器不再有效。 有没有办法绕过这个,以便我能够使用keyup事件? 每次表行从teh ajax调用改变时,是否可以重新绑定它?
这是我如何过滤:
<script type="text/javascript">
var $cellsT = $('table tbody tr td:nth-child(4)'),
$hiddenT = $();
$('input#DocumentType').keyup(function () {
var search = $(this).val();
var $to_hide = $cellsT.filter(function () {
var s = $(this).text().indexOf(search) === -1;
if (s === false) {
foundDocuments = true;
}
return $(this).text().indexOf(search) === -1;
}).parent();
$hiddenT.not($to_hide.get()).show();
$hiddenT = $to_hide.hide();
</script>
你可以做$('input#DocumentType').live("click",function(){});
此外,在jQuery的最新版本,它的最好使用.on()
和.off()
而不是live()
和die()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.