在将焦点设置到元素之后,通过JavaScript将光标放在输入文本元素的文本末尾,最好的方法(我认为是最简单的方法)是什么?
发布于 2010-02-27 09:39:51
试试这个,它对我很有效:
//input is the input element
input.focus(); //sets focus to element
var val = this.input.value; //store the value of the element
this.input.value = ''; //clear the value of the element
this.input.value = val; //set that value back. 为了将光标移动到末尾,输入必须首先具有焦点,然后当值更改时,它将移动到末尾。如果您将.value设置为相同的值,它在chrome中不会改变。
https://stackoverflow.com/questions/511088
复制相似问题