新增< b>< / b>标记到textarea中的选定文本 [英] Add <b></b> tags to selected text in a textarea

查看:77
本文介绍了新增< b>< / b>标记到textarea中的选定文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建一些JavaScript来执行以下操作 - 当用户点击BOLD按钮时,所选文字会获得< b>和< / b>缠在它周围。

 < form name =my> 
< textarea name =textarea>< / textarea>< br />
< input type =buttonvalue =boldonclick =formatText('b'); />
< input type =buttonvalue =italiconclick =formatText('i'); />
< input type =buttonvalue =underlineonclick =formatText('u'); />
< / form>

请帮助我创建用于支持几乎Web浏览器的java脚本

解决方案

您应该使用现有的富文本编辑器,它们是可配置的,以便您可以仅向用户提供您希望他们使用的功能。他们还可以在各种不同的浏览器中工作。



  tinyMCE.init({$ rel =nofollow> tinyMCE 只有粗体,斜体和下划线。 b $ b //常规选项
模式:textareas,
主题:高级,

//主题选项
theme_advanced_buttons1:bold,italic,下划线
});


How to create some javascript to do the following - when the user clicks the "BOLD" button, the selected text gets a "<b> " and a " </b>" wrapped around it.

 <form name="my">
<textarea name="textarea"></textarea><br />
<input type="button" value="bold" onclick="formatText ('b');" />
<input type="button" value="italic" onclick="formatText ('i');" />
<input type="button" value="underline" onclick="formatText ('u');" />
</form> 

please help me to create java-script for supporting almost web browser

解决方案

You should use an existing rich text editor, they are configurable so you can give users only the features what you want them to use. They also have the added benefit of working across a range of different browsers.

An example of setting up tinyMCE with only Bold, Italic and Underline.

tinyMCE.init({
    // General options
    mode : "textareas",
    theme : "advanced",

    // Theme options
    theme_advanced_buttons1 : "bold,italic,underline"
});

这篇关于新增&lt; b&gt;&lt; / b&gt;标记到textarea中的选定文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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