javascript点击按钮显示不必要的`<;部门>`
基于此示例创建了短代码javascript点击按钮显示不必要的`<;部门>`,javascript,html,Javascript,Html,基于此示例创建了短代码 <!doctype html> <html> <head> <title>WYSIWYG Editor</title> </head> <body> <button onclick="displayhtml()">Display HTML</button> <div class="editor" style="width: 50px; he
<!doctype html>
<html>
<head>
<title>WYSIWYG Editor</title>
</head>
<body>
<button onclick="displayhtml()">Display HTML</button>
<div class="editor" style="width: 50px; height: 100px; background-color: white; border: 1px solid grey;" contenteditable="true" spellcheck="true">
</div>
<div class="htmloutput">
</div>
<script>
function displayhtml() {
document.getElementsByClassName("htmloutput")[0].textContent = document.getElementsByClassName("editor")[0].innerHTML;
}
</script>
</body>
</html>
所见即所得编辑器
显示HTML
函数displayhtml(){
document.getElementsByClassName(“htmloutput”)[0]。textContent=document.getElementsByClassName(“编辑器”)[0]。innerHTML;
}
在本地计算机上,在wamp/www内创建索引文件并粘贴代码
在class=“editor”
内键入输入文本。然后单击按钮onclick=“displayhtml()”
我明白了
文本
而不是预期的
文本
在这里试过
好的
为什么在本地计算机上我会看到这些
div
以及如何删除它们?从textbox获取值时,请使用innerText
而不是innerHTML
。用内部文本检查@Tushar
看不到
。如果单击Enter,则希望查看
,而不希望查看div