Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript GetElementByID不工作时出现问题_Javascript_Jquery_Html - Fatal编程技术网

Javascript GetElementByID不工作时出现问题

Javascript GetElementByID不工作时出现问题,javascript,jquery,html,Javascript,Jquery,Html,我尝试了几乎所有可能的代码组合,但显然是正确的。我所要做的就是在javascript/JQuery中按id获取元素,并在警报中显示它。在阅读了一些类似的文章之后,我将脚本放在正文之后,我将代码放在document.ready、window.onload中,但仍然没有任何内容。最终,我有一个按钮和一个带有灰色背景图像的.button css类,还有一个带有白色背景图像的.button:悬停。我想删除.button类并将其替换为具有深灰色背景的.buttonSelected类。短暂性脑缺血发作

我尝试了几乎所有可能的代码组合,但显然是正确的。我所要做的就是在javascript/JQuery中按id获取元素,并在警报中显示它。在阅读了一些类似的文章之后,我将脚本放在正文之后,我将代码放在document.ready、window.onload中,但仍然没有任何内容。最终,我有一个按钮和一个带有灰色背景图像的.button css类,还有一个带有白色背景图像的.button:悬停。我想删除.button类并将其替换为具有深灰色背景的.buttonSelected类。短暂性脑缺血发作

    <div id="PlanningNav">
        <a href="~/Planning/Planning.cshtml">
            <div id="AboutMe" class="Button">
                <img src="~/Resources/Images/icoAbout_Me.jpg" height="20" width="@Button_Width" /> 
                &nbsp;&nbsp;&nbsp;   About Me
            </div>
        </a>
    </div>

<script>
window.onload = function () {
    var button = document.GetElementById('AboutMe');
    alert(button);
};
    $(document).ready(function () {
       var button;
       if (page.indexOf('About') > -1) { 
           button = document.GetElementById('AboutMe');
           alert(button.id); 
           // $('#AboutMe').removeClass('.Button');
           //$('#AboutMe').addClass('.ButtonSelected');
           // alert(button.innerHTML);
        } 
    });
</script>

window.onload=函数(){
var button=document.GetElementById('AboutMe');
警报(按钮);
};
$(文档).ready(函数(){
var按钮;
如果(page.indexOf('About')>-1){
button=document.GetElementById('AboutMe');
警报(按钮id);
//$(“#AboutMe”).removeClass(“.Button”);
//$('#AboutMe').addClass('.ButtonSelected');
//警报(button.innerHTML);
} 
});

JavaScript区分大小写,因此

document.GetElementById('AboutMe');
你需要使用

document.getElementById('AboutMe');

JavaScript区分大小写,因此需要确保大小写正确


您的
GetElementById
将不起作用,正如@dotnetom所说,您需要将其更改为
GetElementById

其GetElementById()没有
GetElementById
但是
getE…
您应该打开控制台并查看错误。应该这样做。另外,不要将Js与jQuery混用,尤其是在jQuery擅长的地方。谢谢,我想这可能是我没有看到的技术性的东西。我确实在visual studio 2015中打开了错误控制台,但没有列出任何错误。