javascript - 一旦我们使用 css 单击单个按钮,如何更改其他两个按钮的不透明背景颜色

标签 javascript jquery html css

您好,我有三个按钮,如果我单击一个按钮,其他两个按钮的背景颜色不透明度应为 40%。以同样的方式,单击其他按钮时它应该相应地改变。提前致谢。 Here is my jsfiddle link

HTML:

<div class="form-group has-feedback ng-scope">                      
 <a href="#"  class="btn btn- newbutton7"><strong style="text-align:center;font-size:17px;font-family: sans-serif;margin-left:-4px;">Annual Compensation</strong></a>
 <a href="#"  class="btn btn- newbutton8"><strong style="text-align:center;font-size:17px;font-family: sans-serif;">Monthly Payslips</strong></a>
 <a href="#"  class="btn btn- newbutton9"><strong style="text-align:center;font-size:17px;font-family: sans-serif;margin-left:-8px;">Investment</strong></a>
 </div>

CSS:

.btn.btn-.newbutton7{

width: 197px;
height: 41px;
margin-top: 56px;

background-color:#01cd27;
color: white;
border-radius: 0px;
font-family: sans-serif;
font-size:15px;
}
.btn.btn-.newbutton8{    
width: 197px;
height: 41px;
margin-top: 56px;   
background-color:#f8b100;
color: white;
border-radius: 0px;
font-family: sans-serif;
font-size:15px;
}
.btn.btn-.newbutton9{    
width: 197px;
height: 41px;
margin-top: -64px;    
background-color:#6b01cd;
color: white;
border-radius: 0px;
font-family: sans-serif;
font-size:15px;
}

最佳答案

试试下面的 jquery 代码:

$('.has-feedback a').click(function(){
$(this).css('opacity',1);
$('.has-feedback a').not(this).css('opacity',0.4);
});

演示:https://jsfiddle.net/xd17xyrm/

或:

CSS:

.opacty {
  opacity:0.4;
}

js:

$('.has-feedback a').not('.has-feedback a:first').addClass('opacty');

$('.has-feedback a').click(function(e){
$('.has-feedback a').not(this).addClass('opacty');
 $(this).removeClass('opacty');

});

演示:https://jsfiddle.net/xd17xyrm/1/

关于javascript - 一旦我们使用 css 单击单个按钮,如何更改其他两个按钮的不透明背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38759172/

相关文章:

javascript - 在文本区域内运行脚本以打印值

javascript - NVD3 - 有没有办法增加气泡的大小?

javascript - jQuery Anchor Clicked 被多次触发

javascript - 创建 mask 叠加聚光灯效果以显示图像

javascript - 在 React 中禁用 onClick 按钮,但仅对 Index 中的一个元素禁用

javascript - 使用 Jquery 克隆 Select2

java - wysiwyg-Jquery HTML 编辑器,用于语法检查,支持所有浏览器

javascript - 如何显示来自 XML 的数据?

Javascript 忽略数字字段上的 novalidate?

HTML/CSS - 在屏幕和打印页面上需要不同的位置