0

这就是我的 java 脚本函数:

function issueOrReturn() {
    var functiontype = document.getElementById("functiontype").value;
    alert("functiontype : "+functiontype);
    if (functiontype=="issueTempcard") {
        alert("1111111111111111111111111");
        var empid = document.getElementById("empid").value;
        var tempcardnumber = document.getElementById("tempcardnumber").value;
        var dateofissue = document.getElementById("dateofissue").value;
        if(empid.length==0) {
            alert("Please enter Employee ID ");
            return false;
        }
        if(tempcardnumber.length==0) {
            alert("Please enter Card Number ");
            return false;
        }
        if(dateofissue.length==0) {
            alert("Please enter Date of issue ");
            return false;
        }
        if(empid.length > 0 && tempcardnumber.length > 0 && dateofissue.length > 0) {
            document.forms["frmTempcard"].submit();
        } else {
            alert("Please enter Employee ID and and Card Number and Date of issue ");
            return false;
        }
    }
    if (functiontype == "returnTempCard") {
        alert("222222222222222222222222222222");
        var empid = document.getElementById("empid").value;
        var dateofreturn = document.getElementById("dateofreturn").value;

        if (empid.length == 0) {
            alert("Please enter Employee ID ");
            return false;
        }
        if (dateofreturn.length == 0) {
            alert("Please enter Date of return ");
            return false;
        }
        if (empid.length > 0 && dateofreturn.length > 0) {
            document.forms["frmTempcard"].submit(); 
        } else {
            alert("Please enter Employee ID and Date of return ");
            return false;
        }
    }
}

这里的函数类型是:issueTempcard打印警报但它没有进入 if 循环issueTempcard因此没有提交表单,

还请告知我以下提交表格的方式是否正确:

if (empid.length > 0 && tempcardnumber.length > 0 && dateofissue.length > 0) {
    document.forms["frmTempcard"].submit(); 
} else {
    alert("Please enter Employee ID and and Card Number and Date of issue ");
}

请为我提供一些帮助,以便我可以做到。

问候,

4

1 回答 1

1

您的两个函数定义都错过了它们的结束}字符。因此,它们不会被执行(因为 javascript 解释器无法读取您的整个函数)

这个JsFiddle显示您的代码可以顺利运行。我所做的就是添加}

为了帮助您调试 JS 代码,请尝试使用Firebug,它可以告诉您哪里出错了;)

Your way of submitting forms looks fine to me, but is also missing the trailing }

于 2012-07-18T10:23:39.257 回答