Substring text with HTML tags in Javascript

前端 未结 6 1315
小蘑菇
小蘑菇 2020-12-14 22:25

Do you have solution to substring text with HTML tags in Javascript?

For example:

var str = \'Lorem ipsum dolor sit         


        
6条回答
  •  庸人自扰
    2020-12-14 22:49

    let str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'
    let plainText = htmlString.replace(/<[^>]+>/g, '');
    

    Extract plain text with above given regular expression then use JS String based ".substr()" function for desired results

提交回复
热议问题