Jquery屏蔽代码不工作为什么? [英] Jquery masking code not working Why?

查看:67
本文介绍了Jquery屏蔽代码不工作为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web表单,我试图掩盖文本框。我有VS2010,ASP.Net使用C#。在网络表单上,我有一个文本框,标签和一个按钮。在css中该页面的代码端,我有jquery代码来掩盖文本框。当我调试代码来测试它时,没有错误,文本框不起作用。我做错了什么?我是jquery的新手。这是Css HTML代码:



I have a Web form that I am trying to mask a textbox. I have VS2010, ASP.Net using C#. On the web form I have a textbox, lables and a button. On the code side of that page in css I have the jquery code to mask the textbox. When I debug the code to test it out there are no errors and the textbox doesn't work. What did I do wrong? I am new to jquery. Here is the Css HTML code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Testcommas.aspx.cs" Inherits="TestNumberCommas.Testcommas" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>jQuery Masked Input Demo</title>
    <script src="Scripts/jquery-2.1.1.min.js" type="text/javascript"></script>
    <script src="Scripts/jquery-2.1.1.js" type="text/javascript"></script>
    <script src="Scripts/jquery-2.1.1-vsdoc.js" type="text/javascript"></script>
    <script src="Scripts/jquery-2.1.1.min.map" type="text/javascript"></script>
    <script src="Scripts/jquery.maskedinput-1.3.1.js" type="text/javascript"></script>
    <script src="Scripts/jquery.maskedinput-1.3.1.min.js" type="text/javascript"></script>
    <script type='text/javascript'>
        $(document).ready(function () {
            $("#TextBoxY").mask("999,999,999,999");
        });

    </script>

    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style2
        {
            width: 245px;
        }
        .style3
        {
            width: 66px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="TextBoxY" runat="server" Width="180px" 

                    AutoCompleteType="Email" ClientIDMode="Static" 

            style="text-align: right"></asp:TextBox>
    </div>
    <table class="style1">
        <tr>
            <td class="style3">
                 </td>
            <td class="style2">
                 </td>
            <td>
                <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit" 

                    Width="100px" />
            </td>
        </tr>
        <tr>
            <td class="style3">
                Hourly</td>
            <td class="style2">
                 </td>
            <td>
                 </td>
        </tr>
        <tr>
            <td class="style3">
                Yearly</td>
            <td class="style2">
                 </td>
            <td>
                 </td>
        </tr>
        <tr>
            <td class="style3">
                 </td>
            <td class="style2">
                 </td>
            <td>
                 </td>
        </tr>
        <tr>
            <td class="style3">
                 </td>
            <td class="style2">
                 </td>
            <td>
                 </td>
        </tr>
        <tr>
            <td class="style3">
                 </td>
            <td class="style2">
                 </td>
            <td>
                 </td>
        </tr>
        <tr>
            <td class="style3">
                 </td>
            <td class="style2">
                 </td>
            <td>
                 </td>
        </tr>
        <tr>
            <td class="style3">
                 </td>
            <td class="style2">
                 </td>
            <td>
                 </td>
        </tr>
    </table>
    </form>
</body>
</html>

推荐答案

document )。ready( function (){
(document).ready(function () {


#TextBoxY)。mask( 999,999,999,999);
});

< / script >

< style type = text / css >
style1
{
width 100%;
}
style2
{
width 245px;
}
style3
{
width 66px;
}
< / style >
< / head > ;
< body >
< 表格 id = form1 runat = 服务器 >
& div >
< asp:TextBox ID = TextBoxY < span class =code-attribute> runat = server 宽度 = 180px

< span class =code-attribute> AutoCompleteType = 电子邮件 ClientIDMode = 静态

< span class =code-attribute> style =\"text-align: right\" ></asp:TextBox >
</div>
<table class=\"style1\">
<tr>
<td class=\"style3\">
 </td>
<td class=\"style2\">
 << span class=\"code-leadattribute\">/td>
<td>
<asp:Button ID=\"Button1\" runat=\"server\" onclick=\"Button1_Click\" Text=\"Submit\"

Width=\"100px\" /
>
</td>
</tr>
<tr>
<td class=\"style3\">
Hourly</td>
<td class=\"style2\">
 </td>
<td>
 </td>
</tr>
<tr>
<td class=\"style3\">
Yearly</td>
<td class=\"style2\">
 </td>
<td>
 </td&g t;
</tr>
<tr>
<td class=\"style3\">
 </td>
<td class=\"style2\">
 </td>
<td>
 </td>
</tr>
<tr>
<td class=\"style3\">
</td>
<td class=\"style2\">
 </td>
<td>
 </td>
</tr>
<tr>
<td class=\"style3\">
 </td>
<td class=\"style2\">
 </td>
<td>
 </td>
</tr>
<tr>
<td class=\"style3\">
 </td>
< td class=\"style2\">
 </td>
<td>
 </td>
</tr>
<tr>
<td class=\"style3\">
 </td>
<td class=\"style2\">
 </td>
<td>
 </td>
</tr>
</table>
</form>
</body>
</html>
("#TextBoxY").mask("999,999,999,999"); }); </script> <style type="text/css"> .style1 { width: 100%; } .style2 { width: 245px; } .style3 { width: 66px; } </style> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBoxY" runat="server" Width="180px" AutoCompleteType="Email" ClientIDMode="Static" style="text-align: right"></asp:TextBox> </div> <table class="style1"> <tr> <td class="style3">  </td> <td class="style2">  </td> <td> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit" Width="100px" /> </td> </tr> <tr> <td class="style3"> Hourly</td> <td class="style2">  </td> <td>  </td> </tr> <tr> <td class="style3"> Yearly</td> <td class="style2">  </td> <td>  </td> </tr> <tr> <td class="style3">  </td> <td class="style2">  </td> <td>  </td> </tr> <tr> <td class="style3">  </td> <td class="style2">  </td> <td>  </td> </tr> <tr> <td class="style3">  </td> <td class="style2">  </td> <td>  </td> </tr> <tr> <td class="style3">  </td> <td class="style2">  </td> <td>  </td> </tr> <tr> <td class="style3">  </td> <td class="style2">  </td> <td>  </td> </tr> </table> </form> </body> </html>


You haven’t mentioned which plugin you’re using - I’m assuming it’s this one[ ^].



You haven't mentioned which plugin you're using - I'm assuming it's this one[^].

<script src="Scripts/jquery-2.1.1.min.js" type="text/javascript"></script>
<script src="Scripts/jquery-2.1.1.js" type="text/javascript"></script>
<script src="Scripts/jquery-2.1.1-vsdoc.js" type="text/javascript"></script>
<script src="Scripts/jquery-2.1.1.min.map" type="text/javascript"></script>



You’ve included the jQuery script three times, and included the source mapping which isn’t needed. Replace those four lines with:


You've included the jQuery script three times, and included the source mapping which isn't needed. Replace those four lines with:

<script src="Scripts/jquery-2.1.1.min.js" type="text/javascript"></script>










<script src="Scripts/jquery.maskedinput-1.3.1.js" type="text/javascript"></script>
<script src="Scripts/jquery.maskedinput-1.3.1.min.js" type="text/javascript"></script>



You’ve included both the normal and minified versions of the plugin script. Replace those two lines with:


You've included both the normal and minified versions of the plugin script. Replace those two lines with:

<script src="Scripts/jquery.maskedinput-1.3.1.min.js" type="text/javascript"></script>







Make sure you have the correct path for the \"Scripts\" folder relative to the page, and that it contains both the jquery-2.1.1.min.js and jquery.maskedinput-1.3.1.min.js files.



Check your browser’s script console for any script errors.



Make sure your AppPool is set to use .NET 4.0, otherwise the ClientIDMode property won’t work.



I’ve just tried your code locally, and it works.




Make sure you have the correct path for the "Scripts" folder relative to the page, and that it contains both the jquery-2.1.1.min.js and jquery.maskedinput-1.3.1.min.js files.

Check your browser's script console for any script errors.

Make sure your AppPool is set to use .NET 4.0, otherwise the ClientIDMode property won't work.

I've just tried your code locally, and it works.


这篇关于Jquery屏蔽代码不工作为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆