How to make selected text bold/italic/underlined in javascript?

后端 未结 3 1745
生来不讨喜
生来不讨喜 2020-12-31 18:40

I\'m trying to work on a webpage that allows users to write their own notes for a school project, and my idea was to let them bold/italicize/underline their text using butto

3条回答
  •  傲寒
    傲寒 (楼主)
    2020-12-31 19:22

    With textarea you cannot achieve that, use divs instead, so you can do something like this:

    $(document).ready(function(){
    $('.boldText').click(function(){
       $('.container').toggleClass("bold");
    });
    $('.italicText').click(function(){
      $('.container').toggleClass("italic");
    });
    $('.underlineText').click(function(){
      $('.container').toggleClass("underline");
    });
    
    
    
    });
    div.container {
        width: 300px;
        height: 100px;
        border: 1px solid #ccc;
        padding: 5px;
    }
    .bold{
      font-weight:bold;
    }
    .italic{
      font-style :italic;
    }
    .underline{
     text-decoration: underline;
    }
    
    

提交回复
热议问题