的console.log(值);我没有记录任何东西,但左边的数字是每次点击都会显示的,它表示调用了console.log(),只是没有显示我放入的内容。
另外,一个问题是,如果javascript位于不同的文件中,我该怎么做呢?谢谢
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>Star Delete</title>
<!--<script type="text/javascript" src="StarDelete.js"></script>-->
</head>
<body>OKAY DELETE STAR YES ;D!
<form>
<input type="text" id="formValueId" name="valueId"/>
<input type="button" id="theButton"/>
</form>
<script type ="text/javascript">
var button = document.getElementById("theButton"),
value = button.form.valueId.value;
//value = document.getElementById("formValueId").value;
button.onclick = function() {
console.log(value);
}
</script>
</body>
</html>
答案 0 :(得分:1)
var button = document.getElementById("theButton"),
value = button.form.valueId.value;
在这里,问题是您在首次加载javascript时声明了值变量,因此它总是空白。