为什么我的Javascript无法正常工作? [英] Why is my Javascript not working?

查看:164
本文介绍了为什么我的Javascript无法正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的Javascript:

 < script type =text / javascript> 
函数contactChange(){
var contact = document.getElementbyId(contact);
if(contact.style.display ==none){
contact.style.display =block;
} else {
contact.style.display =none;
}
}
< / script>

以下是我的网站:

http://www.andrewjalexander.com/

document.getElementById ,而不是 document.getElementbyId 。 (在JS中,变量和函数的名称区分大小写)



调试提示:查看JS控制台(Google Chrome和IE9中的F12,Ctrl + Shift + K在Firefox中)。在这种情况下,可以看到以下错误:

> #< HTMLDocument> 没有方法 getElementbyId )。


This is my Javascript:

<script type="text/javascript">
    function contactChange() {
        var contact = document.getElementbyId("contact");
        if (contact.style.display == "none") {          
            contact.style.display = "block";
        } else {
            contact.style.display = "none";
        }
    }
</script>

And here is my site:

http://www.andrewjalexander.com/

解决方案

It's document.getElementById, not document.getElementbyId. (In JS, name of variables and functions are case-sensitive)

Debugging tip : Look at the JS console (F12 in Google Chrome and IE9, Ctrl+Shift+K in Firefox). In this case, following error can be seen:

It shows where the error happened (line 260 in your HTML/JS code) and what the error is(Object #<HTMLDocument> has no method getElementbyId).

这篇关于为什么我的Javascript无法正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆