简体   繁体   English

隐式声明的javascript变量

[英]javascript variable implicitly declared

so im having an issue with some javascript and html. 所以我有一些JavaScript和HTML的问题。

in my html i have a button set up with an id 在我的HTML我有一个ID设置的按钮

<td><button id = "accept">Accept</button></td>

and in the javascript onload function i have 在javascript onload函数中

acceptButton = document.getElementById("accept");

But for some reason it just started to say, variable implicitly declared , and when i try add anymore javascript, the button does not function. 但是由于某种原因,它刚刚开始说,隐式声明了变量,当我尝试添加更多的javascript时,该按钮不起作用。 I am very new to javascript and really struggling to work out what this issue is due to, can someone maybe shed some light on it? 我对javascript很陌生,并且真的很难弄清楚这个问题是由于什么引起的,也许有人可以对此有所了解吗? thanks 谢谢

I tried adding var, it takes away the error but stops the buttons functionality 我尝试添加var,它消除了错误,但停止了按钮功能

使用var关键字声明变量:

var acceptButton = document.getElementById("accept");

这是因为在加载DOM之前,我已在HTML顶部加载了javascript文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM