admin管理员组文章数量:1333710
I'm using / plugin.
There is an input text with defined mask:
<input type="text" id="txtMyInput" class="FocusSense"/>
and a script:
$(document).ready(function () {
jQuery(function ($) {
$("#txtMyInput").mask("?9.99");
});
$(".FocusSense").focus(function () {
this.select();
});
})
As you can see, I would like select all in txtMyInput
on focus but but alas!
On focus, mask appears and lose .select()
.
What should I do to preserve mask and .select()
?
I'm using http://digitalbush./projects/masked-input-plugin/ plugin.
There is an input text with defined mask:
<input type="text" id="txtMyInput" class="FocusSense"/>
and a script:
$(document).ready(function () {
jQuery(function ($) {
$("#txtMyInput").mask("?9.99");
});
$(".FocusSense").focus(function () {
this.select();
});
})
As you can see, I would like select all in txtMyInput
on focus but but alas!
On focus, mask appears and lose .select()
.
What should I do to preserve mask and .select()
?
- did you tried $(this).select(); ? – insomiac Commented Aug 28, 2012 at 15:33
5 Answers
Reset to default 5I think what you are looking for, is this :
$(document).ready(function () {
jQuery(function ($) {
$("#txtMyInput").mask("?9.99");
});
$(".FocusSense").focus(function (e) {
var that = this;
setTimeout(function(){$(that).select();},10);
return false;
});
});
setTimeout will "queue" the select() execution. So it will select the content after masking is pleted.
Working Demo
you need to use $(this) to get the current object.
$(document).ready(function () {
jQuery(function ($) {
$("#txtMyInput").mask("?9.99");
});
$(".FocusSense").focus(function () {
$(this).select(); // instead of this.select();
});
});
sory change focus change click function;
jQuery(".FocusSense").click(function() {
this.focus();
this.select();
});
this.select() change jQuery(this).select();
$(".FocusSense").focus(function () {
jQuery(this).select();
});
This is duplicate of 'jQuery masked input plugin. select all content when textbox receives focus' where I posted explanation for this fix.
imeout method is unnecessary!
$(".yourMaskedInput").attr("readonly", true).select().removeAttr("readonly");
本文标签: javascriptHow to perform select() on jQuery masked text inputStack Overflow
版权声明:本文标题:javascript - How to perform .select() on jQuery masked text input - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742268941a2443937.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论