admin管理员组文章数量:1430013
so im having an issue with some javascript and html.
in my html i have a button set up with an id
<td><button id = "accept">Accept</button></td>
and in the javascript onload function i have
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. 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? thanks
I tried adding var, it takes away the error but stops the buttons functionality
so im having an issue with some javascript and html.
in my html i have a button set up with an id
<td><button id = "accept">Accept</button></td>
and in the javascript onload function i have
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. 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? thanks
I tried adding var, it takes away the error but stops the buttons functionality
Share Improve this question edited Nov 6, 2017 at 23:21 asked Nov 6, 2017 at 22:38 user8700773user8700773 4-
4
have you actually declared
acceptButton
? tryvar acceptButton = document.getElementById("accept");
– jtate Commented Nov 6, 2017 at 22:39 - acceptButton isn't declared at all, so you should. See What is the purpose of the var keyword and when to use it (or omit it)? – RobG Commented Nov 6, 2017 at 22:41
- Possible duplicate of Declaring variables without var keyword – devlin carnate Commented Nov 6, 2017 at 22:44
- I need to use var? ive been taking javascript classes in university and when doing it the way i showed, we have never used var there :/ ? I just tried that, and it does take away the error im getting but it stops the button from working (button is set up to display a table) – user8700773 Commented Nov 6, 2017 at 22:48
2 Answers
Reset to default 3Use the var
keyword to declare your variable:
var acceptButton = document.getElementById("accept");
It was because I loaded the javascript file at the top of the HTML before the DOM loads
本文标签: htmljavascript variable implicitly declaredStack Overflow
版权声明:本文标题:html - javascript variable implicitly declared - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745508961a2661378.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论