function cursorMove(spos: any) {
// spos 光标的位置 -1为最后一位
var tobj: any = document.getElementsByClassName("van-field__control")[0];
if (spos < 0) spos = tobj.value.length;
if (tobj.setSelectionRange) {
//兼容火狐,谷歌
setTimeout(function() {
tobj.setSelectionRange(spos, spos);
tobj.focus();
}, 0);
} else if (tobj.createTextRange) {
//兼容IE
var rng = tobj.createTextRange();
rng.move("character", spos);
rng.select();
}
}
js控制input输入框的光标位置
最新推荐文章于 2023-07-07 14:47:13 发布