这篇文章主要为大家展示了“web开发中如何将鼠标焦点定位到文本框最后”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“web开发中如何将鼠标焦点定位到文本框最后”这篇文章吧。

经测试,兼容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以上是“web开发中如何将鼠标焦点定位到文本框最后”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联网站建设公司行业资讯频道!
另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。