日期:2014-05-17  浏览次数:20604 次

jquery用母版,验证不了
用jquery文半框验证

普通页面:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default7.aspx.cs" Inherits="Default7" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="../../js/jquery-1.4.2.min.js"></script>
      <script type="text/javascript" language="javascript">
          $(document).ready(function () {
              $("#Button1").click(function () {
                  var txtName = $("#<%=txtName.ClientID%>");
                  var pattern = /^[1][358][0-9]{9}$/;
                  if (pattern.test(txtName.val())) {
                      alert('是手机号');
                  } else {
                      alert('不是手机号');
                  }
              })
          });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button" />
        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
    </div>
    </form>
</body>
</html>

在普通页面,验证好使

调用母版页:

<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/UserControl/MasterPage.Master" CodeBehind="WebForm1.aspx.cs" Inherits="RBKLHKPRO.WebDisplayed.Personal.WebForm1" %>

<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
   <script type="text/javascript" src="../../js/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" language="javascript">
             $(document).ready(function () {
                 $("#Button1").click(function () {
                     var txtName = $("#<%=txtName.ClientID%>");
                     var pattern = /^[1][358][0-9]{9}