我正在使用 JQuery 1.8.16。我在页面上有很多用户控件,如果有的话,我想抓住那些编辑。因此,我在这些用户控件所在的父页面中使用 JQuery 的 Onchange 事件。这是我的 JQuery 代码
$('input[type=text], input[type=file], textarea, select').on("change", function () {
var ctrl = $(this).attr('id');
if (ctrl.indexOf("ddlLibrary") != -1) {
needSave = false;
unlock = true;
UnlockRequest(null);
}
if (ctrl != null && ctrl != "") {
if (ctrl.indexOf("GeneralInformationControl") != -1
|| ctrl.indexOf("PartDetailsControl") != -1
|| ctrl.indexOf("UserInformationControl") != -1
|| ctrl.indexOf("AttachmentControl") != -1) {
if (ctrl.indexOf("lbAttachments") != -1 || ctrl.indexOf("tbAttachmetnDesc") != -1 || ctrl.indexOf("FileUpload1") != -1) {
needSave = false;
window.onbeforeunload = routeUnlock;
unlock = true;
}
else {
needSave = true;
window.onbeforeunload = confirmExit;
unlock = true;
}
}
}
});
首先,我没有发现页面上我的用户控件的任何文本框、下拉列表或 TextArea 发生的任何编辑。其次,我在documen.ready函数中放置了另一个类似的方法来测试如下
//JQuery Function to Call Lock Method on Editing any of the User Controls on Request Page
var locked = false;
$("input,select,textarea").change(function () {
if (!locked) {
$.ajax({
type: "POST",
url: "WebForm1.aspx/methodInServer",
contentType: "application/json; charset=utf-8",
success: function (msg) {
locked = true;
alert(msg.d);
}
});
}
});
});
我在这些函数中设置了断点,令我惊讶的是没有一个断点被命中,并且我对用户控件中的字段的更改没有被捕获。关于为什么会发生这种情况的任何积极想法?