[英]Inserting into a HTML div tag from a javascript function
I have searched online for a solution to my problem, but I can't seem to fix it. 我已经在网上搜索了我的问题的解决方案,但似乎无法解决。 I've tried also using a validator, but still nothing gives. 我也尝试过使用验证器,但仍然没有结果。 Sorry if you think that this is a repeated question. 抱歉,如果您认为这是一个重复的问题。 I just can't seem to find anything. 我似乎什么也找不到。 Here's what I did: 这是我所做的:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p><strong>User Information:</strong></p>
<button onclick="getUserInfo()">Begin</button>
<div id=”content”>Hello</div>
<script type="text/javascript">
function getUserInfo(){
var name = prompt("What is your full name?", "Name");
var age = prompt("How old are you?", "Age");
if (name !== null && age !== null) {
document.getElementById("content").innerHTML =
"Hello, my name is " + name + " and I'm " + age + " years old.";
}
}
</script>
</body>
</html>
Change 更改
<div id=”content”>Hello</div>
to 至
<div id="content">Hello</div>
It might be the issue here. 这可能是这里的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.