代码如下:
<html>
<head>
<title> Welcome Page </title>
</head>
<body>
<h1>Greetings</h1>
<p>
Enter your name: <input type=“text” id=“nameBox” size=12 value="">
</p>
<input type="button" value="Click for Greeting"
onclick="document.getElementById('outputDiv').innerHTML='hello' + document.getElementById('nameBox').value + ', welcome to my page.<br>Do you mind if I call you' + document.getElementById('nameBox').value + '?';">
<hr>
<div id=“outputDiv”></div>
</body>
我得到的只是第 13 行的错误:未捕获的类型错误:无法读取 null 的属性“值”。
我是新手,所以非常感谢帮助!谢谢。
最佳答案
- 您在 html 中使用了弯引号。将“”替换为“”。
size=12
:12
不在引号中。
Demo (在一些字符串文字之前或之后添加空格以使输出字符串更易于阅读。)
关于javascript - 我的文本框 html 代码有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25826376/