[英][object HTMLInputElement]
I made a chat app, but this is just the server.我制作了一个聊天应用程序,但这只是服务器。 I'm not very good at JS, but this code doesn't do what it's supposed to.我不是很擅长 JS,但是这段代码没有做它应该做的事情。
from flask import Flask
app = Flask('app')
@app.route('/')
def hello_world():
return 'Chat app \
<br> \
<h1 id="p1">text<h1> \
<input id="text2"> \
<button onclick="chat()">Chat</button> \
<script> \
function chat(){ \
document.getElementById("p1").innerHTML = document.getElementById("text2"); \
} \
</script>'
app.run(host='0.0.0.0', port=8080)
It should replace p1 with the text of text2, but instead it replaces it with "[object HTMLInputElement]."它应将 p1 替换为 text2 的文本,但它却将其替换为“[object HTMLInputElement]”。
Can you help me?你能帮助我吗?
document.getElementById("p1").innerHTML = document.getElementById("text2")
will return a string version of element itself.将返回元素本身的字符串版本。 It seems like you want the value
of the element, which will be the user input:看起来你想要元素的value
,这将是用户输入:
function chat(){ document.getElementById("p1").innerHTML = document.getElementById("text2").value; }
Chat app <br> <h1 id="p1">text<h1> <input id="text2"> <button onclick="chat()">Chat</button>
document.getElementById("p1").innerHTML = document.getElementById("text2").value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.