我正在尝试检测页面上的所有文本框和下拉列表,并检查它们在窗口卸载时是否有更改。问题是,我可以检测文本框但不能检测下拉列表。这是我的做法。
$(document).ready(function () {
var warnMessage = 'Warning: You have unsaved changes.';
$('input:not(:button,:submit),input[type="text"],select').each(function () {
var elem = $(this);
// Save current value of element
elem.data('oldVal', elem.val());
// Look for changes in the value
elem.bind("propertychange keyup input paste", function (event) {
// If value has changed...
if (elem.data('oldVal') != elem.val()) {
window.onbeforeunload = function () {
if (warnMessage != null) return warnMessage;
else warnMessage = 'Warning: You have unsaved changes.';
}
}
});
});
$('input:submit,#addLiquidFillButton,#addCommentButton,#addManualRegenButton,#addStateMileageButton').click(function (e) {
warnMessage = null;
});
});
附加信息。我使用以下代码创建下拉列表:
<asp:DropDownList ID="LocationIdDDL" CssClass="ddl" runat="server" AutoPostBack="true"></asp:DropDownList>
我假设通过添加“选择”将检查所有下拉列表,但现在,它没有。有任何想法吗?谢谢!