JavaScript RegExp match text ignoring HTML

后端 未结 6 1962
时光取名叫无心
时光取名叫无心 2020-12-09 22:28

Is it possible to match \"the dog is really really fat\" in \"The dog is really really fat!\" and add \"

6条回答
  •  甜味超标
    2020-12-09 23:15

    If you use jQuery, you can use the text property on the element containing the text you're searching for. Given this markup:

    The dog is really really fat!

    This would yield "The dog is really really fat!":

    $('#the-text').text();
    

    You could do your regex search on that text instead of trying to do so in the markup.

    Without jQuery, I'm unsure of an easy way to extract and concatenate the text nodes from all child elements.

提交回复
热议问题