javascript - 如何将其作为字符串而不是 html 元素返回?

标签 javascript php html web

如何将其作为字符串而不是 html 元素返回?

<script>
function myFunction() {
  var str = "<input type='text'/>";
  var res = str.toString();
  document.getElementById("demo").innerHTML = res;
}
</script>

This is the return result

最佳答案

尝试使用 textContent 而不是 innerHTML

关于javascript - 如何将其作为字符串而不是 html 元素返回?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43578984/

相关文章:

html - angular2 - 使用 flexbox 设置组件的高度

html - 让右列紧挨着左列,而不是右对齐

javascript - 仅在 jQuery Mobile 中抑制某些链接的 AJAX/哈希行为

php——仅用于搜索目录和 .jpg 的 glob

php - Symfony2 : How to inject ALL parameters in a service?

php - preg_match foreach

javascript - 缓存 this 引用

javascript - 如何通过点击另一个div中的li来显示不同div中的文本?

javascript - Express,在静态文件中展开变量

html - 使用 Node.js 提供动态网页