0

可以这么说,我一直在用头撞墙。我正在使用此处找到的 jquery.maskedinput 插件: https ://raw.github.com/digitalBush/jquery.maskedinput/1.3.1/dist/jquery.maskedinput.js 注意:我更正了第 29 行的语法错误. 这里提到了这个问题: 为什么我的这个掩码代码出现 JavaScript 解析器错误? 我读到 maskedinput.1.3 和 jquery.1.9 可能存在一些兼容性问题,所以我使用了此处提供的迁移:http: //jquery.com/download/ 回到旧版本只会产生更多错误。我遇到的问题是 Firefox 抛出“TypeError:$(...).mask 不是函数,第 21 行。

测试.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs"
    Inherits="Test.test" %>
<!DOCTYPE html>
<html>
<head>

<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link type="text/css" rel="stylesheet" href="styles.css" />
<link type="text/css" rel="stylesheet" href="css/jquery-ui-1.8.12.custom.css" />
<link type="text/css" rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
<script type="text/javascript" src="../Scripts/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.js"></script>
<script type="text/javascript" src="../Scripts/jquery.maskedinput.min.js"></script>

<%-- Begin Phone Validation Script  --%>
<script type="text/javascript">
    $(document).ready(function () {
        //Input Mask for landline phone number
        $("#<%=phone_num1.ClientID%>").mask("(999) 999-9999");
        $("#<%=phone_num2.ClientID%>").mask("(999) 999-9999");
    });
</script>
<%-- End of Phone Validation Script  --%>
</head>
<body onload="initialize()">
<form runat="server">
  <div id="consent-form-container">
        <div class="box">
            <table>
                <tr>
                    <td>
                        <asp:Label ID="Label14" runat="server" Text="Phone 1:"></asp:Label>
                    </td>
                    <td>
                       <asp:TextBox ID="phone_num1" runat="server" CssClass="client_home_ph"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="phone_validation1" runat="server" ControlToValidate="phone_num1" ErrorMessage="*" Font-Bold="True" ForeColor="Red"></asp:RequiredFieldValidator>
                    </td>
                </tr>

                <tr>
                    <td>
                        <asp:Label ID="Label17" runat="server" Text="Phone 2:"></asp:Label>
                    </td>
                    <td>
                        <asp:TextBox ID="phone_num2" runat="server" CssClass="client_home_ph"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="phone_validation2" runat="server" ControlToValidate="phone_num2" ErrorMessage="*" Font-Bold="True" ForeColor="Red"></asp:RequiredFieldValidator>
                    </td>
                </tr>
            </table>
        </div>
   </div>
</form>
</body>
</html>

代码中断的 jquery.maskedinput.js 代码片段

$.mask = {
//Predefined character definitions
definitions: {
    '9': "[0-9]",
    'a': "[A-Za-z]",
    '*': "[A-Za-z0-9]"
},
dataName: "rawMaskFn",
placeholder: '_'
};

有趣的是,我差不多一周前就开始工作了,然后我添加了更多脚本,这发生了哈哈。任何帮助是极大的赞赏 :)

4

1 回答 1

0

好的,我终于想通了。这是我解决此问题的方法...

调试它很困难并且需要一些时间,但基本上你必须使用旧版本的 jquery 并像这样升级它

<script src="Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="http://code.jquery.com/jquery-1.9.0.js" type="text/javascript"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.js" type="text/javascript></script>

您调用您的“旧”jquery 版本并通过插入 1.9 和迁移插件进行更新,如上所示。

于 2013-05-28T15:19:32.693 回答