这是对我的代码的简化,但我认为这个例子有效。基本上,我想要做的就是使用jQuery自动突出显示选定的div元素。无法让jQuery addClass(“active”)正常工作
目前,只要按住元素(背景变为橙色),div元素只会显示为“活动”。
<html>
<head>
<title>Samuels HTML-inlämning!</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js">
</script>
<script type="text/javascript">
$('.test').click(function(){
$('.test').removeClass("active");
$(this).addClass("active");
});
</script>
<style type="text/css">
div.test{
background: grey;
}
div.test:hover{
background: yellow;
}
div.test.active{
background: orange;
}
</style>
</head>
<body>
<div class="test">
Stuff
</div>
<div class="test">
Other stuff
</div>
<div class="test">
More Stuff
</div>
</body>
</html>
有没有人知道为什么这不起作用?完整的例子基本上是一样的,但我是一个ID来选择类未被突出显示,而不是(.test)所有类。但是,该代码产生相同的结果。
UPDATE:
试图使在CSS这种变化:
div.test.active{
background: orange;
}
现在不highligt都不过。我错过了什么?
活动不是一个类它是一个伪类 – vlio20