扩展jQuery---选中指定索引的文本

<script type="text/javascript">
//1。扩展jQuery
$.fn.selectRange = function (start, end) {
var curObj = $(this).get(0);
if (!curObj) return;
else if (curObj.setSelectionRange) {
curObj.focus(); curObj.setSelectionRange(start, end);
} /* WebKit */
else if (curObj.createTextRange) {
var range = curObj.createTextRange();
range.collapse(true);
range.moveEnd('character', end);
range.moveStart('character', start);
range.select();
} /* IE */
else if (curObj.selectionStart) {
curObj.selectionStart = start;
curObj.selectionEnd = end;
}
};
</script>

posted @ 2019-03-10 13:52  咖啡无眠  阅读(295)  评论(0编辑  收藏  举报