Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript点击按钮显示不必要的`<;部门>`_Javascript_Html - Fatal编程技术网

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