JS caret to selection by pressing button in IE

2019-09-09 13:14发布

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.htmlText);

But when I press button, the text on the button is being selected, not in the text field.
Is there a workaround for this?

1条回答
做自己的国王
2楼-- · 2019-09-09 13:39

FOCUS to textfield is answer

查看更多
登录 后发表回答