jQuery蒙面输入插件.文本框获得焦点时选择所有内容

Jon*_*son 10 javascript jquery jquery-plugins

这是这个问题的后续问题:

在获得焦点时选择文本框的所有内容(Javascript或jQuery)

基本上我使用的文本框与jQuery蒙版输入插件一起使用(编辑:链接可能不再指向相关版本)

当蒙版输入文本框获得焦点时,我想选择该文本框的所有内容,但似乎将此插件绑定到文本框可以防止这种情况.我只是想知道是否有办法解决这个问题.

下面是一个示例.html页面,演示了该问题:

<html>
<head>
    <title></title>
</head>
<body>
    <input id="masktest" type="text" value="01/01/2009" />
    <br />
    <input id="focustest" type="text" value="on focus will select all contents..." />

    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script type="text/javascript" src="http://jquery-joshbush.googlecode.com/files/jquery.maskedinput-1.2.1.pack.js"></script>
    <script type="text/javascript">
        $(function() {
            $("#masktest").mask("99/99/9999");

            // Contents of textboxes will be selected when receiving focus.
            $("input[type=text]")
                .focus(function() {
                    $(this).select();
                });
        });
    </script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

Jos*_*ush 7

我是jQuery 的Masked Input Plugin的作者.我决定这应该是已完成掩码的默认行为,我将其纳入最新版本.你可以在这里阅读详细信息