簡體   English   中英

為什么Javascript innerHTML自動在我的字符串中添加引號?

[英]Why Javascript innerHTML add quote automatically to my string?

我正在嘗試在div添加一些HTML代碼和文本。 如果我僅添加文本,則沒有任何問題。 但是,如果我用HTML代碼添加一些文本,它將自動在文本中添加引號。

 <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <title></title> <script> function test() { document.getElementById("viewer1").innerHTML = "text";// this is not add any quote to text document.getElementById("viewer2").innerHTML = "text <b>Bold Text</b>"; //this is add quote to text but not add quote to <b>Bold Text</b> } </script> </head> <body> <div id="viewer1"></div> <div id="viewer2"></div> <button onclick="test()">Test it</button> </body> </html> 

看起來像這樣

  viewer1 content = text viever2 content ="text" <b>Bold Text</b> 

我不要引號。 如何將其刪除?

看下面的截圖:

在此處輸入圖片說明

引號不會顯示在網頁上。 它僅適用於chrome控制台節點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM