开发者

JS caret to selection by pressing button in IE

开发者 https://www.devze.com 2022-12-22 05:00 出处:网络
I have a caret in the textarea (no selection). I need to make selection out of it by pressing a button.

I have a caret in the textarea (no selection). I need to make selection out of it by pressing a button.

For example: "This is a te|xt"

var range = document.selection.createRange ();
range.moveEnd('character');
range.select();
alert (range.htmlTe开发者_如何转开发xt);

But when I press button, the text on the button is being selected, not in the text field.

Is there a workaround for this?


FOCUS to textfield is answer

0

精彩评论

暂无评论...
验证码 换一张
取 消