- object.selectionStart;
- object.selectionEnd;
- // object就是textarea的物件
- this.object.focus();
- var range = document.selection.createRange();
- var stored_range = range.duplicate();
- stored_range.moveToElementText(this.object);
- stored_range.setEndPoint('EndToEnd', range);
- // 此selectionStart就是游標的起點
- this.object.selectionStart = stored_range.text.length - range.text.length;
- // 此selectionEnd就是游標的終點
- this.object.selectionEnd = this.object.selectionStart + range.text.length;
No comments:
Post a Comment