为什么 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 控制台节点。
我正在尝试在 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 控制台节点。