有一个问题是获得输出,如果可以帮助我请帮助我
<!Doctypehtml>
<html>
<title>new html</title>
<head>
</head>
<body>
<button id="open">click me</button>
<script >
var open1=document.getElementById("open");
var n="hi";
open1.addEventListener("click", function(){
alert(n.length);
});
</script>
</body>
</html>
答案 0 :(得分:2)
在事件名称之后你忘记了:
var open1=document.getElementById("open")
var n="hi";
open1.addEventListener("click", function(){
alert(n.length);
});
答案 1 :(得分:2)
以下是您的更新代码:您在“点击”后错过了逗号(,)。
<!Doctypehtml>
<html>
<title>new html</title>
<head>
</head>
<body>
<button id="open">click me</button>
<script>
var open1=document.getElementById("open")
var n="hi";
open1.addEventListener("click",function(){
alert(n.length);
});
</script>
</body>
</html>
答案 2 :(得分:0)
<!Doctypehtml>
<html>
<title>new html</title>
<head></head>
<body>
<button id="open">click me</button>
<script >
var open1=document.getElementById("open")
var n="hi";
open1.addEventListener("click",function(){
alert(n.length);
});
</script>
</body>
</html>
点击
后,您错过了“,”