开发者

selecting text of textbox on focus

Hi I have added some format on textbox like $0.00 now what i wants is to remove the format on focus and then select the value of text box code is :

$("#controlId").focus(function(){
   $(this).val(this.val().replace(/\$/g, ''));
   $(thi开发者_如何学编程s).select();
});

this is working fine in IE and firefox but not in Google Chrome.

Can some body suggest me what should i do for this?


.val() is a jQuery function, so it should look like this:

$("#controlId").focus(function(){
   $(this).val($(this).val().replace(/\$/g, ''));
   $(this).select();
});

Or a bit more concise/chained:

$("#controlId").focus(function(){
   $(this).val(function(i, v) { return v.replace(/\$/g, ''); }).select();
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜