javascript - 禁用 div 后,将其内容更改为禁用颜色或 css?

标签 javascript jquery html css

我在 <div> 中有按钮和图像.当我做 <div>禁用。它的内容不像禁用那样变灰。我仍然可以像启用一样。

如何更改 div 内容背景以禁用颜色(透明)?

<div style="display:inline-block" id="divImgAddOrUpdate" >  
   <button id="imgAddOrUpdate" type="submit" class="btn"  >
            <img src="Images/save.png" alt="" />Add/Update
   </button>
</div>

JS

<script type="text/javascript">
         $('#divImgAddOrUpdate').prop('disabled', true);
         $('#divImgAddOrUpdate *').prop('disabled', true);
</script>

CSS

 .btn {      

    border:.1em #868686 solid; 
    -webkit-border-radius: 4px; 
    -moz-border-radius: 4px;
    border-radius: 4px;
    font-size: 1em;
    font-family:Segoe UI; 
    padding: 5px 10px 5px 5px; 
    text-decoration:none; 
    display:inline-block;
    text-shadow: 0px 0px 0 rgba(0,0,0,0.3);
    text-align:left;
    color: #000000;
    background-color: #f4f5f5; 
    background-image: linear-gradient(to bottom, #f4f5f5, #dfdddd);
 }
.btn:hover{
    border:1px solid #bfc4c4;
    background-color: #d9dddd; background-image: linear-gradient(to bottom, #d9dddd, #c6c3c3);
}
.btn img {
    vertical-align:middle;
}

JSFiddle

最佳答案

您可以尝试使用 :disabled 伪类和 :not 伪类,如下所示:

/* this is edited from your original style */
.btn:not(:disabled):hover{
    border:1px solid #bfc4c4;
    background-color: #d9dddd; background-image: linear-gradient(to bottom, #d9dddd, #c6c3c3);
}
/* this is added */
.btn:disabled {
   color:grey;
   background-color:gray;
}
/* style for graying out the img */
.btn:disabled > img {    
   filter:gray;
   -webkit-filter:grayscale(100%);
   -moz-filter:grayscale(100%);    
   filter:grayscale(100%);
}

这是 working fiddle

关于javascript - 禁用 div 后,将其内容更改为禁用颜色或 css?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22751729/

相关文章:

javascript - 使用 jQuery 将参数动态传递到 YouTube API

javascript - 如何使用angularjs从下拉列表中获取值

javascript - 检查 touchend 是否在拖动之后出现

php - HTML5 网络存储与 Cookie

javascript - 无法使用ajax加载c3图形数据

javascript - Jquery ajax 返回排序后的数据

html - CSS动画弹跳(带曲线)

javascript - 随机点 Javascript/CSS 开始运行非常慢

javascript - 如果需要,显示字段

javascript - 使用 JS 将嵌套对象的键展平为数组