$.fn.setCursorPosition = function( pos )
{
this.each( function( index, elem ) {
if( elem.setSelectionRange ) {
elem.setSelectionRange(pos, pos);
} else if( elem.createTextRange ) {
var range = elem.createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
}
});
return this;
};
3번째 indexd에 위치
$("#test").focus().setCurserPosition(3);
<html>
<body>
<div>
<input type="text" id="test"/>
</div>
</body>
</html>
'Javascript' 카테고리의 다른 글
배열 (0) | 2021.02.18 |
---|