简体   繁体   English

如何正确更改背景不透明度

[英]How to change background opacity correctly

So I have a div which includes a form with many input fields. 因此,我有一个div,其中包含带有许多输入字段的表单。

If I click on a button all the input fields are getting disabled and the opacity of these input fields should change to around 0.2. 如果单击按钮,则所有输入字段都将被禁用,这些输入字段的不透明度应更改为0.2。

Also an image kinda pops up, (it style.display was set to none , and now onclick to block ) So while the opacity of the elements gets perfectly disabled and are made transparent, the onclick from the image that pops up doesn't work, if there is an input field in the background. 还会弹出一个图像,(它的style.display设置为none ,现在通过onclick进行block )因此,虽然完全禁用了元素的不透明度style.display其设为透明,但弹出的图像的onclick无效,如果背景中有一个输入字段。

Is there a way to not complicity vanish the input fields but still being able to press the image at every pixel? 有没有一种方法可以避免共谋消失,但仍然能够在每个像素处按下图像?

<div><img id="i" style="display:none" onclick=dothis(event) src="dsds.png" /></div>
<div id="d"><input id="c" onclick="dis()" type=button value="hey"><input id="f" type=text ></div>

<script>

function dis(){
document.getElementById("i").style.display="block";
document.getElementById("d").style.opacity="0.2";
document.getElementById("c").disable=true;
document.getElementById("f").disable=true;
}

to change opacity on click, you can use jquery as shown: 要更改点击的不透明度,可以使用jquery,如下所示:

 $(document).ready(function() { $("#button").click(function(){ $("#content_to_fade").css('opacity', '0.2'); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script> <div> <p id="content_to_fade">Test</p> <button id="button">Button</button> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM