首页 > 代码库 > 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判断表单内容是否更改过