Главная > Javascript > maskedinput курсор в начало

maskedinput курсор в начало

$.fn.setCursorPosition=function(pos){
	if($(this).get(0).setSelectionRange){
		$(this).get(0).setSelectionRange(pos,pos);
	}
	else if($(this).get(0).createTextRange){
		var range=$(this).get(0).createTextRange();
		range.collapse(true);
		range.moveEnd('character',pos);
		range.moveStart('character',pos);
		range.select();
	}
};
function set_mask_cursor(){
	$('input[name="phone"]').on('click',function(){
		$(this).setCursorPosition(4);
	});
	$('input[name="code"]').on('click',function(){
		$(this).setCursorPosition(0);
	});
}
$(document).ready(function(){
	$("input[name=phone]").mask("+7 (999) 999-99-99");
	$("input[name=code]").mask("9999");
	set_mask_cursor();
});
Categories: Javascript Tags:
  1. Пока что нет комментариев.
Похожие публикации