Matching and highlighting tags/words (changing color and font-weight) inside textarea using jQuery

后端 未结 4 1064
后悔当初
后悔当初 2021-01-25 10:31

I\'ve textarea where I just start typing when I add tags which I define in array so based on my condition it should say in array but it is

4条回答
  •  花落未央
    2021-01-25 10:56

    $(document).on('keyup', function(e) {
    
    var yourstring =$("P").html().match("{(.*)}")
    
       
    for (i=0; i< yourstring.length; i++){
    
    $('p:contains('+yourstring[i]+')', document.body).each(function(){
          
          $(this).html($(this).html().replace(
                new RegExp(yourstring[i], 'g'), ''+yourstring[i]+''
          ));
    });
    }
    });
    .someclass {
        color: blue;
        font-weight: bold;
    }
    
    

    Lorem Ipsum is simply {email} {rec1_email} dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's printer took a galley of type and scrambled it to make a type specimen book. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, printe book.

提交回复
热议问题