简体   繁体   English

如何在 HTML/javascript/jquery 中单击时激活粗体标签并在再次单击时停用

[英]how to activate bold tags when click and deactivate when click again in HTML/javascript/jquery

I would like to know if there's a way in HTML/javascript/jquery to create the bold button like in MS.WORD.我想知道在 HTML/javascript/jquery 中是否有办法创建像 MS.WORD 中那样的粗体按钮。

When we click the bold button, any text we type in the textbox/textarea will be bold but when we click the button again, any text we type will be normal again but the bolded text will still be bold当我们单击粗体按钮时,我们在文本框/文本区域中输入的任何文本都将是粗体,但是当我们再次单击该按钮时,我们输入的任何文本将再次正常但加粗文本仍将是粗体

any suggestion will be highly appreciated thanks任何建议将不胜感激谢谢

There isn't a built in way to do this, since presentation and data are separated through CSS and HTML.没有内置的方法可以做到这一点,因为表示和数据是通过 CSS 和 HTML 分开的。 There are a number of html5 wysiwyg editors that provide this ability有许多 html5 所见即所得编辑器提供此功能

  1. wysihtml5所见即所得
  2. bootstrap-wysiwyg引导程序-所见即所得
  3. raptor editor猛禽编辑

and many more还有很多

There are a number of different plugins to accomplish what you are asking.有许多不同的插件可以完成您的要求。 For example the TinyMCE jQuery plugin .例如TinyMCE jQuery 插件

If you dont want tinymce style editor then try this one please http://jsfiddle.net/Ys5ZU/2/如果你不想要 tinymce 风格的编辑器,那么请试试这个http://jsfiddle.net/Ys5ZU/2/

I added jquery, but you could do it without it.我添加了 jquery,但你可以不用它。

$(document).ready(function () {
    $("#change").click(function(){
        $("#text").toggleClass("big");
        $("#text").hasClass("big")?$("#change").val("bold"):$("#change").val("normal")
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM