JS通过在IE中按下按钮来选择 [英] JS caret to selection by pressing button in IE

查看:81
本文介绍了JS通过在IE中按下按钮来选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在textarea有一个插入符号(没有选择)。我需要通过按下来选择

例如:这是一个te | xt

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?

推荐答案

FOCUS to textfield is answer

FOCUS to textfield is answer

这篇关于JS通过在IE中按下按钮来选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆