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");
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742268941a4412331.html
评论列表(0条)