Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法读取空javascript的属性值_Javascript_Asp.net - Fatal编程技术网

无法读取空javascript的属性值

无法读取空javascript的属性值,javascript,asp.net,Javascript,Asp.net,这是我的js代码: function validate_reg() { try { if (document.getElementById('txtFname').value == "") { alert("enter 2"); document.getElementById('lblFnameError').style.color = "red"; document.getElementById(

这是我的js代码:

function validate_reg() {
    try {

        if (document.getElementById('txtFname').value == "") {
            alert("enter 2");
            document.getElementById('lblFnameError').style.color = "red";
            document.getElementById('lblFnameError').innerHTML = "Error : Enter First NameD.";
            document.getElementById('txtFname').focus();
            validate_reg_suc = false;
            return false;
        }
        validate_reg_suc = true;
        alert("done");
    } catch (exc) {
        alert("Error : " + exc);
        return false;
    }
}
我的html:

<table style="width:100%;">

    <tr>
        <td style="width:200px;"></td>
        <td style="width:257px;">

        </td>
        <td>

        </td>
    </tr>

    <tr>
        <td style="width:200px;">Select AccSelect Account Type&nbsp;</td>
        <td style="width:257px;">
            <select runat="server" clientidmode="Static"  style="width:250px;" id="cmbAType">
                <option value="0">SELECT</option>
                <option value="REVIWER">REVIWER</option>
                <option value="CANDIDATE">CANDIDATE</option>
            </select>
        </td>
        <td>
            <label id="lblAtype" style="color:Red">Validation   </td>
    </tr>

    <tr>
        <td style="width:200px;">User Type</td>
        <td style="width:257px;">
            <select runat="server" clientidmode="Static"  style="width:250px;" id="cmbUtype">
                <option value="0">Select</option>
                <option value="Dr.">Dr.</option>
                <option value="Miss">Miss</option>
                <option value="Mr">Mr</option>
                <option value="Mrs">Mrs</option>
                <option value="Ms">Ms</option>
                <option value="Prof">Prof</option>
            </select>
        </td>
        <td>
            <label id="Label1" style="color:Red">Validation</label>
        </td>
    </tr>

    <tr>
        <td style="width:200px;">First Name</td>
        <td style="width:257px;">
            <input clientidmode="Static" runat="server" style="width:250px;" id="txtFname" type="text" />
        </td>
        <td>
            <label id="lblFnameError" style="color:Red">Validation</label>
        </td>
    </tr>

    <tr>
        <td style="width:200px;">Middle Name</td>
        <td style="width:257px;">
            <input runat="server" clientidmode="Static"  style="width:250px;" id="txtMname" type="text" />
        </td>
        <td>
            <label id="Label3" style="color:Red">Validation</label>
        </td>
    </tr>

    <tr>
        <td style="width:200px;">Last Name</td>
        <td style="width:257px;">
            <input runat="server" clientidmode="Static"  style="width:250px;" id="txtLname" type="text" />
        </td>
        <td>
            <label id="Label4" style="color:Red">Validation</label>
        </td>
    </tr>

    <tr>
        <td style="width:200px;">Degree</td>
        <td style="width:257px;">
            <input runat="server" clientidmode="Static"  style="width:250px;" id="Text4" type="text" />
        </td>
        <td>
            <label id="Label5" style="color:Red">Validation</label>
        </td>
    </tr>

    <tr>
        <td style="width:200px;">Email ID</td>
        <td style="width:257px;">
            <input runat="server" clientidmode="Static" style="width:250px;" id="Text5" type="text" />
        </td>
        <td>
            <label id="Label6" style="color:Red">Validation</label>
        </td>
    </tr>
    <tr>
        <td style="width:200px;"></td>
        <td style="width:257px;">
    <asp:Button ID="btnRegister" CausesValidation="true" OnClientClick="return validate_reg()" runat="server" Text="Register" 
                onclick="btnRegister_Click" />
    <input id="Reset1" type="reset" value="reset" />
</td>
<td>
    <label id="Label7" style="color:Green">Message</label>
</td>
</tr>
</table>

选择帐户选择帐户类型
挑选
校订者
候选人
验证
用户类型
挑选
博士
错过
先生
夫人
太太
教授
验证
名字
验证
中名
验证
姓
验证
度
验证
电子邮件ID
验证
消息

js在html后调用,但仍然出现此错误

'txtFname'在您的html中不存在,或者ID中有输入错误。这是您在上使用的唯一元素
.value
,并且错误状态为null表示无法获取您引用的元素。txtFname存在:,您能解释更多吗,如何解决此错误?请帮助我解决此错误