gpt4 book ai didi

javascript - jQuery 屏蔽输入插件。当文本框获得焦点时选择所有内容

转载 作者:可可西里 更新时间:2023-11-01 02:37:28 25 4
gpt4 key购买 nike

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

select all contents of textbox when it receives focus (Javascript or jQuery)

基本上,我将文本框与 jQuery masked input plugin 结合使用(编辑:链接可能不再指向相关版本)

当被屏蔽的输入文本框获得焦点时,我想选择该文本框的所有内容,但似乎将此插件绑定(bind)到文本框会阻止这种情况。我只是想知道是否有办法解决这个问题。

下面是演示该问题的示例 .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>

最佳答案

我是 Masked Input Plugin 的作者对于 jQuery。我决定这应该是已完成掩码的默认行为,并将其添加到最新版本中。详情可以看here

关于javascript - jQuery 屏蔽输入插件。当文本框获得焦点时选择所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/480979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com