JQuery在asp.net ajax updatepanel中提交之后就失效。这是因为ASP.NET页面POST BACK之后,脚本绑定的事件处理方法失效而导致。
解决方案一:使用live函数(纯jquey实现,这种效果会比较好)
$(function () {
$('#checkAll').click(function () {
if (this.checked) {
$(':input').attr('checked', true);
} else {
$(':input').attr('checked', false);
}
});
});
修改为:
$(function () {
$('#checkAll').live("click", function () {
if (this.checked) {
$(':input').attr('checked', true);
} else {
$(':input').attr('checked', false);
}
});
});
解决方案二:将代码写入body元素 的load事件
function pageload(){
$('#checkAll').live("click", function () {
if (this.checked) {
$(':input').attr('checked', true);
} else {
$(':input').attr('checked', false);
}
});
}
<body load="pageload" > //页面代码</body>