Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 禁用div后,是否将其内容更改为禁用颜色或css?_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 禁用div后,是否将其内容更改为禁用颜色或css?

Javascript 禁用div后,是否将其内容更改为禁用颜色或css?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我在中有按钮和图像。当我将设置为禁用时。它的内容不会像禁用一样变灰。我仍然可以像enable一样做同样的事情 如何更改div内容背景以禁用颜色(透明) 您可以尝试使用:disabled伪类和:not伪类,如下所示: /* this is edited from your original style */ .btn:not(:disabled):hover{ border:1px solid #bfc4c4; background-color: #d9dddd; backgrou

我在
中有按钮和图像。当我将
设置为禁用时。它的内容不会像禁用一样变灰。我仍然可以像enable一样做同样的事情

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


您可以尝试使用
: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%);
}

以下是禁用div todo什么?对于
div
元素(或除交互式表单元素以外的任何其他元素,
input
textarea
select
等),$('divImgAddOrUpdate').prop('disabled','disabled')@jp310:
disabled
(XHTML之外)是一个布尔属性:它要么在那里,要么不在那里,它不需要值。为什么不向div添加另一个类呢?例如:$('divImgAddOrUpdate').addClass(“div禁用”);正如David提到的,disabled属性仅在表单元素上有效。感谢您的代码。可以用图像(内部按钮)灰显吗?@James123我更新了代码以及用于灰显图像的提琴。
<script type="text/javascript">
         $('#divImgAddOrUpdate').prop('disabled', true);
         $('#divImgAddOrUpdate *').prop('disabled', true);
</script>
 .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;
}
/* 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%);
}