js获得焦点后光标移到末尾

来源:互联网 发布:家庭购物记账软件 编辑:程序博客网 时间:2024/05/22 09:38
<script language="javascript"> 
function setFocus() 

var obj = event.srcElement; //获得焦点对象
var txt =obj.createTextRange(); //用createTextRange来创建Range对象操作文本
txt.moveStart('character',obj.value.length); //修改文档的开始节点,向后移动长度
txt.collapse(true); 
txt.select(); 

</script> 
<input type="text" value="abcdefg123456789" onfocus="setFocus()">
0 0
原创粉丝点击