Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.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 无法读取属性';removeClass';空的_Javascript_Jquery_Tabs - Fatal编程技术网

Javascript 无法读取属性';removeClass';空的

Javascript 无法读取属性';removeClass';空的,javascript,jquery,tabs,Javascript,Jquery,Tabs,我尝试在joomla中使用jquery,使用Sourcerer插件来创建选项卡,但这并不重要 我的代码可以在JSFIDLE和local.html文档中完美运行,但不能在live网站上运行 它写道* 未捕获的TypeError:无法读取null的属性“removeClass” 七弦琴 下面是一个代码: $(函数(){ $('.tabs')。在('click','a',函数(e)上{ e、 预防默认值(); $hash=this.hash; $link=$(此项); 如果($link.pare

我尝试在joomla中使用jquery,使用Sourcerer插件来创建选项卡,但这并不重要

我的代码可以在JSFIDLE和local.html文档中完美运行,但不能在live网站上运行

它写道*

未捕获的TypeError:无法读取null的属性“removeClass”

  • 七弦琴
下面是一个代码:

$(函数(){
$('.tabs')。在('click','a',函数(e)上{
e、 预防默认值();
$hash=this.hash;
$link=$(此项);
如果($link.parent('.active')){
$('.tabs block.active').removeClass('active');
$('div.active').removeClass('active');
$($hash).addClass('active');
$link.parent().addClass('active');
}
})
})
.tabs块div{display:none;}
.tabs li{显示:内联块;}
ul.tabs{margin:0;position:relative;top:2px;}
.tabs li{边框:实心2px#448ebe;边框底部:无;边框半径:5px 5px 0;}
.tabs li.active{背景颜色:#fff;边框颜色:#66b366;不透明度:1;}
.tabs块div.active{显示:块;边框:实心#66b366 2px;边框半径:5px;左填充:10px}

表1

表2

表3

表4


您能仔细检查一下您的逻辑吗

$('.tabs-block .active').removeClass('active');
$('div.active').removeClass('active');
在第一行中,您正在删除类“active”,它也将从下面的元素中删除

<div class="active" id="tab1">

elment将成为:

<div id="tab1">


现在,没有带有活动类的div,您的第二条语句将找不到任何匹配的元素,您将得到异常。

如何在html主页中包含此js?它是在一个单独的js文件中吗?是的,在单独的文件中,它看起来像这样,但在包含的
html
文件中,我没有看到任何
tabs.js
@user2181397的引用。是的,对不起,它在writent-htmlProblem按脚本顺序运行后立即运行,我将jquery放在模板头中,现在一切都正常了。哈哈,我写了3个不同的脚本来理解这个问题。现在我知道js稍微多了一点xDi修复了这个问题,现在有了
$link.parent不是一个函数
D:first post comments中的解决方案