internet explorer 6 - How to select a character range in a textarea using Javascript? - Stack Overflow

Simple question - is there any way to select a sub-set of the text displayed in a <textarea> cont

Simple question - is there any way to select a sub-set of the text displayed in a <textarea> control using Javascript?

e.g. have a function like

selectText(startCharNo, endCharNo, textareaName);

It also needs to be IE6 patible.

Simple question - is there any way to select a sub-set of the text displayed in a <textarea> control using Javascript?

e.g. have a function like

selectText(startCharNo, endCharNo, textareaName);

It also needs to be IE6 patible.

Share Improve this question asked Apr 29, 2009 at 7:53 Richard NicholsRichard Nichols 1,94018 silver badges19 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

yes, it is possible

element.focus();
if(element.setSelectionRange)
   element.setSelectionRange(startCharNo, endCharNo);
else {
   var r = element.createTextRange();
   r.collapse(true);
   r.moveEnd('character', endCharNo);
   r.moveStart('character', startCharNo);
   r.select();   
}

element is the reference to the textarea

createTextRange()

http://www.developerfusion./forum/thread/48987/

selectText(startCharNo, endCharNo, textAreaName){
   var content = document.getElementById(textAreaName).innerHTML; //value may work too
   var piece = content.subString(startCharNo, endCharNo);
   return piece;
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745562589a4633194.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信