Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.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 为什么不是';t document.ready()是否正在处理此页?_Javascript_Jquery - Fatal编程技术网

Javascript 为什么不是';t document.ready()是否正在处理此页?

Javascript 为什么不是';t document.ready()是否正在处理此页?,javascript,jquery,Javascript,Jquery,因此,我有一个简单的jquery代码来突出显示nav菜单 $(document).ready(function(){ $('#header .mm a').each(function(){ if( $(this).attr('href') == window.location.href ){ $(this).addClass('active'); } var value = window.location.href.substring(window.l

因此,我有一个简单的jquery代码来突出显示nav菜单

$(document).ready(function(){
$('#header .mm a').each(function(){

    if( $(this).attr('href') == window.location.href ){
        $(this).addClass('active');
    }

    var value = window.location.href.substring(window.location.href.lastIndexOf('/') + 1);

    if( $(this).attr('href') == '/site/' && (value == '') ){
        $(this).addClass('active');
    }

});
});
在此页面上,请点击此处:

我不知道为什么代码不能运行。控制台中没有错误。

复制粘贴此:

<script type="text/javascript">
$(document).ready(function(){
  $('#header .mm a').each(function(){

    if( $(this).attr('href') == window.location.href ){
        $(this).addClass('active');
    }

    var value = window.location.href.substring(window.location.href.lastIndexOf('/') + 1);

    if( $(this).attr('href') == '/site/' && (value == '') ){
        $(this).addClass('active');
    }

  });
});
</script>

$(文档).ready(函数(){
$('#header.mm a')。每个(函数(){
if($(this.attr('href')==window.location.href){
$(this.addClass('active');
}
var value=window.location.href.substring(window.location.href.lastIndexOf('/')+1);
if($(this.attr('href')='/site/'&&(value=''){
$(this.addClass('active');
}
});
});

查看页面源代码,所涉及的脚本不在任何标记之间。您可以看到它在页面底部的页脚下方发出。

代码不在脚本标记内。修复这个问题,它应该可以正常工作。

代码在身体的上方或下方?哦,我的上帝。你有没有尝试访问他链接的网站?!你怎么知道它没有运行?您是否向代码添加了
console.log()
调用?