問題描述
這是這個問題的后續(xù)問題:
This is a followup question to this question:
選擇文本框的所有內(nèi)容當(dāng)它獲得焦點時(Javascript 或 jQuery)
基本上我將文本框與 jQuery 屏蔽輸入插件結(jié)合使用(鏈接可能不再指向相關(guān)版本)
Basically I am using a textbox in conjunction with the jQuery masked input plugin( Link may no longer point at relevant version)
當(dāng)被屏蔽的輸入文本框獲得焦點時,我想選擇該文本框的所有內(nèi)容,但似乎將此插件綁定到文本框會阻止這種情況.我只是想知道是否有辦法解決這個問題.
When the masked input textbox receives focus I want to select all of the contents of that textbox, but it seems as though having this plugin binded to the textbox prevents that. I was just wondering if there was a way around this.
以下是演示該問題的示例 .html 頁面:
Below is a sample .html page that demonstrates the issue:
<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>
推薦答案
我是 用于 jQuery 的屏蔽輸入插件.我決定這應(yīng)該是已完成掩碼的默認(rèn)行為,并將其放入最新版本.您可以閱讀詳細(xì)信息這里
I'm the author of the Masked Input Plugin for jQuery. I decided that this should be the default behavior for completed masks and I got it into the latest release. You can read the details here
這篇關(guān)于jQuery 屏蔽輸入插件.當(dāng)文本框獲得焦點時選擇所有內(nèi)容的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!