You need to check to see if the user has modified the contents of a form, you can use the method provided in this article, return True if the contents of the form are modified, return false without modification, and a friend with a need can refer to the next
Sometimes, you need to check to see if the user has modified the contents of a form, you can use the following tips, which returns true if the contents of the form are modified, and False if the contents of the form are not modified. The code is as follows:
Copy Code code as follows:
function Formisdirty (form) {
for (var i = 0; i < form.elements.length; i++) {
var element = Form.elem Ents[i];
var type = Element.type;
if (type = = CheckBox | | | type = = "Radio") {
if (element.checked!= element.defaultchecked) {
return true;
}
}
Else if (type = = Hidden | | | type = = "Password" | | | type = = "Text" | | | type = = "textarea") {
if (ele Ment.value!= element.defaultvalue) {
return true;
}
}
Else if (type = = Select-one | | | type = = "Select-multiple") {
for (var j = 0; J < Element.optio Ns.length; J + +) {
if (element.options[j].selected!= element.options[j].defaultselected) {
return true;
}
}
}
}
return false;
}
Window.onbeforeunload = function (e) {
E = e | | window.event;
if (Formisdirty (document.forms["Someform"])) {
if (e) {
E.returnvalue = "You have unsaved changes.";
}
Return "have unsaved changes."
}
};