这里我有一些代码:
HTML
<div>
<div class="ca_button"><a href="javascript:void(0)" class="ca_button" onClick="setQuality(-100, 'price_quality', '{$lang501}/{$lang502}');">1 button</a></div>
<div class="ca_button1"><a href="javascript:void(0)" class="ca_button1" onClick="setQuality(100, 'price_quality', '{$lang501}/{$lang502}');">2 button</a></div>
</div>
<div>
<div class="ca_button"><a href="javascript:void(0)" class="ca_button" onClick="setQuality(100, 'parameter2', '{$lang501}/{$lang502}');">1 button</a></div>
<div class="ca_button1"><a href="javascript:void(0)" class="ca_button1" onClick="setQuality(100, 'parameter2', '{$lang501}/{$lang502}');">2 button</a></div>
</div>
JS
var rating_quality = new Array();
function setQuality(qulaity, type_rating, name)
{
//alert('test' + qulaity + ' ->' + type_rating + ' ' + name);
rating_quality[type_rating] = qulaity;
if(qulaity > 0)
{
//console.log($('#id_adv_' + type_rating).length);
if ($('#id_adv_' + type_rating).length == 0)
{
$('#id_add_adventage').append("<div id='id_adv_" + type_rating + "'>" + name + "</div>");
$('#id_disadv_' + type_rating).remove();
$('#id_add_adventage').css('font-size', '12');
$(this).css('background-color', '#9C0');
}
}
else
{
if ($('#id_disadv_' + type_rating).length == 0)
{
$('#id_add_disadventage').append("<div id='id_disadv_" + type_rating + "'>" + name + "</div>");
$('#id_adv_' + type_rating).remove();
$('#id_add_disadventage').css('font-size', '12');
$(this).css('background-color', '#C00');
}
}
//console.log('------------ispis-------------');
/*for(key in rating_quality)
{
console.log('key:'+ key + ' ' + rating_quality[key]);
}
*/
}
css
.ca_button {
display: inline-block;
text-decoration: none;
padding: 10px 20px;
text-align: center;
background-color: #BABABA;
border-color: #FFFFFF;
border-width: 1px;
-webkit-border-radius: 4px 0px 0px 4px;
border-radius: 4px 0px 0px 4px;
border-style: solid;
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
line-height: 120%;
color: #FFF;
-moz-border-radius: 4px 0px 0px 4px;
min-height:8px;
margin-top:15px;
margin-left:48px;
}
.ca_button1 {
display: inline-block;
text-decoration: none;
padding: 10px 20px;
text-align: center;
background-color: #BABABA;
border-color: #FFFFFF;
border-width: 1px;
-webkit-border-radius: 0px 4px 4px 0px;
border-radius: 0px 4px 4px 0px;
border-style: solid;
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
line-height: 120%;
color: #FFF;
-moz-border-radius: 0px 4px 4px 0px;
width:73px;
min-height:15px;
margin-top:15px;
}
.button1:hover {
background-color: #91B522;
color: #FFF;
}
.button1:active {
background-color: #91B522;
color: #FFF;
}
.button1:visited {
background-color: #91B522;
color: #FFF;
}
在这里,当我单击 1button 更改颜色时,我也需要单击 2button 更改 2button 上的颜色,但也需要 1button 失去颜色...所有这些都不会影响第二个 div 上的 1button 和 2button ...我怎么能去做?有没有办法做到这一点?谢谢!