[英]Onclick button input does not work
This below code is like a chat page.There are a text type input and button type input at the bottom of the page which are fixed.My idea is whenever i write something in text input and then click on button the message goes to a new created div. 下面的代码就像一个聊天页面。页面底部有一个文本类型输入和按钮类型输入,它们是固定的。我的想法是每当我在文本输入中写一些东西然后单击按钮时消息就会转到新的创建了div but it does not work .Any help would be appreciated.
但它不起作用。任何帮助将不胜感激。 thanks
谢谢
<script>
function updatePageMsg() {
var msg = document.getElementById("Text").value;
var divElement = document.createElement("div");
divElement.setAttribute("style", "background-size:cover; padding: 5px 5px 5px 5px ;width:200px;height:200px");
var pElement = document.createElement("p");
pElement.innerText = msg;
divElement.appendChild(pElement);
rightDiv = document.getElementById("rightdiv");
rightDiv.appendChild(divElement);
}
</script>
<div style="margin-top:50px ; background-size:cover;background-attachment:fixed;position:absolute;top:0;left:0;right:0;bottom:0"">
<div id="rightdiv" style="width:30%;left:0 ; height:100% ; background-color:yellow;float:left ; overflow:scroll"></div>
<div style="width:70%;right:0 ; height:100% ; background-color:red;float:left ; overflow:scroll"></div>
</div>
<div style="position:fixed ; bottom:3px ; width:100% ; background-size:cover; left:0 ;text-align:center">
<div>
<input id="Text" type="search" value="Enter your Message here" style="font-size:20px" size="100"/>
<input onclick="updatePageMsg()" id="SendBtn" type="button" value="Send" style="font-size:20px ; bottom:6px" />
</div>
</div>
Use pElement.innerHTML = msg;
使用
pElement.innerHTML = msg;
instead of pElement.innerText = msg;
而不是
pElement.innerText = msg;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.