如何从jquery中的文本区域中选择文本? [英] How to get selected text from a text area in jquery?

查看:133
本文介绍了如何从jquery中的文本区域中选择文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我从文本区域中选择一个文本我需要知道选择了哪个文本,例如hello world如果我选择你好我想看看你好如何选择如何在jquery中执行此操作。我希望大胆。

If i select a text from a text area i need to know which text is selected, for example "hello world" if i select hello i would like to see hello is selected how can i do this in jquery. and i want to make it bold.

<textarea id="editor" cols="80" rows="20">
   Hello world, This is Me!
</textarea> 
<button onclick="SelectText()">
  Bold
</button>


推荐答案

要将所选内容设为粗体,您可以不要直接在textarea中这样做,但你可以使用可编辑的div来做到这一点。这个插件可以帮到你: http://mistic100.github.io/jquery-highlighttextarea/

About to make the selected content as bold, you can't do that directly in the textarea but you can do that using editable divs. This plugin could help you: http://mistic100.github.io/jquery-highlighttextarea/

关于你的评论:如何从div中获取除html标签之外的所有文本?你可以使用这样的东西:jQuery('。yourDiv')。text();

About your comment: "How can i get the all text from a div excluding html tags?" you can use something like this: jQuery('.yourDiv').text();

这篇关于如何从jquery中的文本区域中选择文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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