I need to make some part of my string bold using replace function

前端 未结 1 1464
抹茶落季
抹茶落季 2021-01-28 23:01

I need to make some part of my string bold using the replace function. "b" and "strong" tags do not work within the string as "<" part of tag di

相关标签:
1条回答
  • 2021-01-28 23:39

    Supposing that you know the text to be put in bold... There is a JS string function bold().

    This can help you...

    <!DOCTYPE html>
    <html>
    <body>
    
    <p>Click the button to display a string in bold.</p>
    
    <button onclick="myFunction()">Try it</button>
    
    <p id="demo"></p>
    
    <script>
    function myFunction() {
      var str = "Hello World!";
      var result = "The " + str.bold() + " is in bold";
      document.getElementById("demo").innerHTML = result;
    }
    </script>
    
    </body>
    </html>
    

    Check: https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_str_bold

    0 讨论(0)
提交回复
热议问题