对象 HTMLTextAreaElement javascript 对 document.write 的响应
object HTMLTextAreaElement javascript response on document.write
为什么我不能通过Javascript/Jquery让var yourName显示在文本中?通过我尝试过的所有方法,它给了我 [object HTMLTextAreaElement] 作为响应。我做错了什么?
Javascript:
var yourName = window.prompt("please enter name")
HTML + Javascript:
<div id="info"><p>
<script>document.write(yourName)</script>, your job is...
</p><div>
它不是 PHP 它不会呈现您的 html "in place"。您必须创建一个 "container",然后例如更改其 innerHTML.
你可以这样实现,例如:
HTML:
<div id="info"><p>
<b id="thename"></b>, your job is...
<div>
JS:
var yourName = window.prompt("please enter name")
document.getElementById("thename").innerHTML = yourName
为什么我不能通过Javascript/Jquery让var yourName显示在文本中?通过我尝试过的所有方法,它给了我 [object HTMLTextAreaElement] 作为响应。我做错了什么?
Javascript:
var yourName = window.prompt("please enter name")
HTML + Javascript:
<div id="info"><p>
<script>document.write(yourName)</script>, your job is...
</p><div>
它不是 PHP 它不会呈现您的 html "in place"。您必须创建一个 "container",然后例如更改其 innerHTML.
你可以这样实现,例如:
HTML:
<div id="info"><p>
<b id="thename"></b>, your job is...
<div>
JS:
var yourName = window.prompt("please enter name")
document.getElementById("thename").innerHTML = yourName