将鼠标焦点定位到文本框最后
2017-01-11 10:56
197 查看
经测试,兼容IE8
//设置焦点相关---begin //用法:$("#txtInput").val("你好").focusEnd(); $.fn.setCursorPosition = function (position) { if (this.lengh == 0) return this; return $(this).setSelection(position, position); } $.fn.setSelection = function (selectionStart, selectionEnd) { if (this.lengh == 0) return this; input = this[0]; if (input.createTextRange) { var range = input.createTextRange(); range.collapse(true); range.moveEnd('character', selectionEnd); range.moveStart('character', selectionStart); range.select(); } else if (input.setSelectionRange) { input.focus(); input.setSelectionRange(selectionStart, selectionEnd); } return this; } $.fn.focusEnd = function () { if (this.val() != undefined) { this.setCursorPosition(this.val().length); } } //设置焦点相关---end
相关文章推荐
- 将鼠标焦点定位到文本框最后
- 将鼠标焦点定位到文本框最后(代码分享)
- 文本框获取焦点后如何将光标定位到文本最后
- Selenium示例集锦--常见元素识别方法、下拉框、文本域及富文本框、鼠标操作、一组元素定位、弹窗、多窗口处理、JS、frame、文件上传和下载
- 文本框提示样式,鼠标点击获得焦点时提示内容消失
- 鼠标焦点离开文本框时验证的js代码
- 如何能实现文本框默认值,鼠标单击后消失,当鼠标焦点消失默认值又出现
- js实现文本框中焦点在最后位置
- js设置文本框中焦点位置在最后的示例代码(简单实用)
- 鼠标焦点离开文本框时验证
- Jquery实现文本框得到焦点的时候,文本框的焦点出现在最后!
- 鼠标焦点离开文本框时验证的js代码
- js实现文本框中焦点在最后位置
- jquery关于页面焦点的定位(文本框获取焦点时改变样式 )
- 鼠标点击清空文本框 失去焦点显示提示信息
- 焦点落在文本框的最后
- winform 中,以编程方式将光标定位到文本框的最后并将滚动条滚动到该位置
- js设置文本框中焦点位置在最后的示例代码(简单实用)
- 使用jQuery实现文本框input定位到文字最后(兼容所有浏览器)
- jquery关于页面焦点的定位(文本框获取焦点时改变样式 )