JS判斷表單內容是否更改過

來源:互聯網
上載者:User

標籤:

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判斷表單內容是否更改過

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.