当前位置:编程学习 > JS >>

asp.net的js中获取控件的ClientID

<tr>
                        <td width="110" height="35" align="center" style="font-weight: bolder">
                            出生年月
                        </td>
                        <td style="font-size: 14px">
                            <asp:TextBox ID="txtBirth" ReadOnly="true" runat="server"></asp:TextBox>
                        </td>
                        <td width="110" height="28" align="center" style="font-weight: bolder">
                            性别
                        </td>
                        <td style="font-size: 14px">
                            <asp:TextBox ReadOnly="true" ID="txtSex" runat="server"></asp:TextBox>
                        </td>
                    </tr>

 

这是很普通的两个控件,但是我们一旦结合母版页,控件ID中就会出现一下母版页特有的表示,js货jQuery获取不便。那么怎么办呢?

 

<script language="javascript">
        $(function () {
            var 易做图Id = "<%=txtSex.ClientID %>";
            var birthId = "<%=txtBirth.ClientID %>";
            $('.idcardClass').blur(function () {
                var id = $(this).val();
                if (IdCardValidate(id)) {
                    showBirthdayAndSex(id, 易做图Id, birthId);
                }
                else {
                    $("#" + 易做图Id).val("");
                    $("#" + birthId).val("");
                    alert("你输入的身份证号有误");
                    return false;
                }
            });
        });
</script>

 

摘自 徐越的专栏
补充:Web开发 , ASP.Net ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,