Javascript 为什么不是';t document.ready()是否正在处理此页?
因此,我有一个简单的jquery代码来突出显示nav菜单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
$(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()
调用?