我有一个JS代码,当

checkQueryString != "M"


但是当值变为checkQueryString == "M"时,它不会进入循环

这是我的代码。

function GridExpInfo_ClientAdd(record) {
        var checkQueryString = '<%= Request.QueryString["Mode"] %>';
        if (checkQueryString != "M") {
            if ($('input:checked').length > 0) {

                document.getElementById("GridExpInfo_tplRowEdit3_ctl00_txtExpRefNo").disabled = true;
                document.getElementById("GridExpInfo_tplRowEdit3_ctl00_txtExpRefDt").disabled = true;

                document.getElementById('GridExpInfo_tplRowEdit3_ctl00_ddlStageType').value = "";
                var last_value = 0;
                var last_text;

                var checkboxlist = document.getElementById('ddlStatus');
                var checkOptions =   checkboxlist.getElementsByTagName('input');
                var listSelected = checkboxlist.getElementsByTagName('label');

                for (i = 0; i < checkOptions.length; i++) {
                    if (checkOptions[i].checked == true) {
                        last_text = listSelected[i].innerText;
                        last_value =  checkOptions[i].value;
                        document.getElementById('GridExpInfo_tplRowEdit3_ctl00_ddlStageType').innerHTML = "";
                        var ObjPriOptionExp = document.createElement("OPTION");
                        ObjPriOptionExp.text = last_text;
                        ObjPriOptionExp.value = last_value;
                        document.getElementById('GridExpInfo_tplRowEdit3_ctl00_ddlStageType').add(ObjPriOptionExp);
                    }
                }
            }
            if(checkQueryString == "M")
            {
               alert('Value is M now');
            }
            else {
                alert('Kindly select the stage');
            }
        }
    }


所以我的问题是,为什么它与if匹配时为什么不进入M

最佳答案

因为

if (checkQueryString == "M") {
    alert('Value is M now');
} else {
    alert('Kindly select the stage');
}


内有if (checkQueryString == "M")

所以试试这个

function GridExpInfo_ClientAdd(record) {
    var checkQueryString = '<%= Request.QueryString["Mode"] %>';
    if (checkQueryString != "M") {
        if ($('input:checked').length > 0) {

            document.getElementById("GridExpInfo_tplRowEdit3_ctl00_txtExpRefNo").disabled = true;
            document.getElementById("GridExpInfo_tplRowEdit3_ctl00_txtExpRefDt").disabled = true;

            document.getElementById('GridExpInfo_tplRowEdit3_ctl00_ddlStageType').value = "";
            var last_value = 0;
            var last_text;

            var checkboxlist = document.getElementById('ddlStatus');
            var checkOptions = checkboxlist.getElementsByTagName('input');
            var listSelected = checkboxlist.getElementsByTagName('label');

            for (i = 0; i < checkOptions.length; i++) {
                if (checkOptions[i].checked == true) {
                    last_text = listSelected[i].innerText;
                    last_value = checkOptions[i].value;
                    document.getElementById('GridExpInfo_tplRowEdit3_ctl00_ddlStageType').innerHTML = "";
                    var ObjPriOptionExp = document.createElement("OPTION");
                    ObjPriOptionExp.text = last_text;
                    ObjPriOptionExp.value = last_value;
                    document.getElementById('GridExpInfo_tplRowEdit3_ctl00_ddlStageType').add(ObjPriOptionExp);
                }
            }
        }

    } else if (checkQueryString == "M") {
        alert('Value is M now');
    } else {
        alert('Kindly select the stage');
    }
}

关于javascript - JavaScript条件无法正常运行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40080900/

10-10 06:01