爲什麼不addClass工作?點擊與類step
div div背景和字體顏色應該改變,但沒有發生。addClass不工作?
<html>
<head><style type="text/css">
.currentstep {
background-color:#eeb345; padding:5px; color:#000000; font-size:14px; font-family:Arial;
}
#stepcontainer {
overflow:hidden; width:100%;
}
.step {
float:right; width:auto; margin-right:2px; background-color:#59758d; padding:5px; color:#FFFFFF; font-size:14px; font-family:Arial; cursor:pointer;
}
</style>
<script type="text/javascript">
$(function(){
$('.step').live('click',function() {
$(this).addClass('currentstep');
$(this).siblings('.step').removeClass('currentstep');
});
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<div id='stepcontainer'><div id='reset'><a>Reset</a></div>
<div class='step'>Step 3</div><div class='step'>Step 2</div><div class='step'>Step 1</div></div>
</body></html>
只是把你的腳本src放在jQuery代碼上面。 – sumi
class * currenttep *在class * step *之前指定,所以* step *的規則優先。更改樣式表中的順序(這就是**級聯**樣式表應該如何工作)。 – RobG