javascript - Select all text on focus in numbers fields -
javascript - Select all text on focus in numbers fields -
i have aspx text box class num_input
. should allow numbers , automatically add together comma separator:
$('.num_input').live("keyup", function () { $(this).numeric(); var num = $(this).val().replace(/(,)/g, ''); $(this).val(num.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,")); });
we have new requirement select text when user navigates through others textbox using tab or placing cursor in text.
i tried utilize
$(this).select();
but didn't work!!
jquery's select
function isn't @ dedicated selecting text.
if need that,
this.selectionstart = 0; this.selectionend = this.value.length;
you can define function letting select text of jquery element :
$.fn.selecttext = function(){ this.each(function(){ this.selectionstart = 0; this.selectionend = this.value.length; }); }
demonstration
javascript jquery
Comments
Post a Comment