经测试,兼容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
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持移动技术网!
如对本文有疑问, 点击进行留言回复!!
使用纯前端JavaScript实现Excel导入导出方法过程详解
微信小程序完美解决scroll-view高度自适应问题的方法
bootstrap-closable-tab可实现关闭的tab标签页插件
网友评论