为什么我的jquery输入掩码不起作用? [英] Why is my jquery input mask not working?

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

问题描述

我正在尝试使用jQuery输入蒙版插件(jquery.maskedinput-1.3.min.js),并且我搜索了几个示例/解决方案,并且我的代码与其他工作示例完全相同,但它只是不会为我工作.请记住,我的代码目前仅测试此插件(试图使其工作,这将解释为什么我试图将日期输入掩码应用于名称字段)我的代码位于:

I am trying to use the jQuery input mask plug-in (jquery.maskedinput-1.3.min.js), and I have searched for several examples/solutions, and my code is exactly as other working examples, but it simply won't work for me. Keep in mind my code is only testing this plug-in for now (trying to get it to work, which will explain why I am trying to apply a date input mask to a name field) My code lies below:

HTML

<!DOCTYPE html>

<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>Persons of Interest</title>
    <link rel="stylesheet" type="text/css" href="/Default_Styler.css" />
    <link rel="shortcut icon" href="/person.ico" type="image/x-icon" />
    <script src="/Scripts/jquery.1.7.2.js" type="text/javascript"></script>
    <script src="/Scripts/jquery.maskedinput-1.3.min.js" type="text/javascript"></script>
    <script src="/Scripts/FormHandler.js" type="text/javascript"></script>
</head>
<body>
    <div id="WrapperDiv">
        <div id="TitleBar">    <!--Beginning of Title Bar-->
            <div style="padding-top: 30px; text-align: center;">Persons of Interest</div>
        </div>                 <!--End of Title Bar-->
        <div id="FormHolder">
            <form action="">
                <p><label>POI Name: </label><input type="text" id="POI Name" name="POI Name" value=""/></p>
            </form>
        </div>
    </div>
</body>
</html>

JavaScript

jQuery(function ($) {
    $("#POI Name").mask("99/99/9999");
});

除此之外,我可以向您保证所引用的jQuery库确实在 适当的目录. (/脚本/...)

Other than that, I can assure you that the referenced jQuery libraries are indeed in the appropriate directory. (/Scripts/...)

单击输入字段或其他任何内容都不会出现错误,它只是什么也没做.

I don't get an error when I click in the input field or anything, it just simply does nothing.

推荐答案

jQuery选择器遵循标准CSS语法,因此ID中间的空格实际上被视为后代选择器.让您的生活更轻松:使用jQuery时,请将ID和类限制为字母数字,连字符,仅此而已.

jQuery selectors follow the standard CSS syntax, so the space in the middle of your ID is actually being treated as a descendant selector. Make your life easier: when dealing with jQuery, keep your IDs and classes limited to alphanumerics, hyphen and that's about it.

为了澄清:jQuery中有一个引号/转义语法,但是恕我直言,它太烦人了,因此我什至没有给出示例.

To clarify: there is a quote/escape syntax in jQuery, but IMHO it's too annoying to deal with, hence I'm not even giving an example of it.

这篇关于为什么我的jquery输入掩码不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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