简体   繁体   中英

How to replace text with html

I am trying to replace a phone number with a new phone number.
However, it's not working with the <p> tags right now.

I can replace it with a word and it changes it. But when I use HTML it doesn't work

<script>
$(function() {
$("#navbarPhoneNumber").html("<p id='phonenumber'></p>");
});
</script>

对于这个简单的例子,不要使用 jquery,只需使用 DOM 的简单 API 函数.getElementById

document.getElementById('navbarPhoneNumber').innerText = <new phone number>

You can use innerHTML after you get your element to replace your text


  
  document.getElementById("navphonenumber").innerHTML = phonenumber;

Here is a solution I wrote

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM