我用js控制文本框的聚焦问题
但是 focus 后光标只聚焦到文字的最前面
如何聚焦到文字的最后面呢?
如:
<input type="text" value="here is the test text" id="txta"/>
当 document.getElementById("txta").focus()的时候光标在here 之前
我要放在 text之后这么写?
但是 focus 后光标只聚焦到文字的最前面
如何聚焦到文字的最后面呢?
如:
<input type="text" value="here is the test text" id="txta"/>
当 document.getElementById("txta").focus()的时候光标在here 之前
我要放在 text之后这么写?
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 4</title></head><body>
<input type=text value="123" id="test" />
</body></html>
<script language="javascript">
function getSelectPos(obj){
var esrc = document.getElementById(obj);
if(esrc==null){
esrc=event.srcElement;
}
var rtextRange =esrc.createTextRange();
rtextRange.moveStart('character',esrc.value.length);
rtextRange.collapse(true);
rtextRange.select();
}
test.focus();
getSelectPos("test");
</script>
<script language="javascript">
function setFocus()
{
var obj = event.srcElement;
var txt =obj.createTextRange();
txt.moveStart('character',obj.value.length);
txt.collapse(true);
txt.select();
}
</script>
<input type="text" value="http://toto369.net" onfocus="setFocus()">