js设置文本框中焦点位置在最后的示例代码(简单实用)

时间:2014-03-04    点击:76   

在火狐浏览器中直接使用this.focus();即可实现。

在IE中,在this.focus();之后再把文本框的值赋给文本框,焦点即在最后了。很简单哟!!

如:

复制代码 代码如下:

var tar=document.getElementByIdx_x("name");
if(tar.attachEvent){
tar.attachEvent('onmouseover',focus(tar),false);
}else{
tar.addEventListener('mouseover',focus(tar),false);
}
function focus(tar){

    tar.focus();
    tar.value=tar.value;
}

JavaScript程序员应该知道的45个实用技巧
js 判断js函数、变量是否存在的简单示例代码
js 事件截取enter按键页面提交事件示例代码
js判断页面中是否有指定控件的简单实例
js实现文本框中焦点在最后位置
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved