JS判断表单内容是否更改过
Posted 名扬博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JS判断表单内容是否更改过相关的知识,希望对你有一定的参考价值。
1,根据具体标签判断
function JudgesubmitForm() { var judjeWs = false; var judjeAt = false; var judjeWd = false; var ws = document.getElementById(‘WorkOrderStatusList‘);//下拉框 var wsold = ws.options[ws.selectedIndex].value; var At = document.getElementById(‘AlarmHandleTypeList‘);//下拉框 var Atold = At.options[At.selectedIndex].value; var wd = document.getElementById(‘OrderHandle‘);//输入框 //At.options[At.selectedIndex].defaultSelectedif (wsold!="") { console.log("修改WS"); judjeWs = true; } if (Atold != "") { console.log("修改AT"); judjeAt = true; } if (wd.value != wd.defaultValue) { console.log("修改Wd"); judjeWd = true; } if (judjeWs == true||judjeAt == true||judjeWd == true) { return true; } else { return false; } }
2遍历所有的form标签
function JudgesubmitForm() { var form = document.getElementById(‘ImgForm‘); for (var i = 0; i < form.length; i++) { var element = form.elements[i]; var type = element.type; if (type == "checkbox" || type == "radio") { if (element.checked == element.defaultChecked) { console.log("没有选择单选或多选框"); } } if (type == "hidden" || type == "password" || type == "text" || type == "textarea") { if (element.value == element.defaultValue) { console.log("没有进行文本输入"); } } if (type == "select-one" || type == "select-multiple") { for (var j = 0; j < element.options.length; j++) { if (element.options[j].selected == element.options[j].defaultSelected) { console.log("没有选择下拉框"); } } } if (type == "file") { if (element.value.length == 0) { Filechange = false; console.log("没选择图片"); } } }
以上是关于JS判断表单内容是否更改过的主要内容,如果未能解决你的问题,请参考以下文章