首页 > 代码库 > JS判断表单内容是否更改过
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 =http://www.mamicode.com/= element.defaultValue) {"没有进行文本输入"); } } 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判断表单内容是否更改过
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。