Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.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
Jquery 单击重置Css值_Jquery_Html_Css - Fatal编程技术网

Jquery 单击重置Css值

Jquery 单击重置Css值,jquery,html,css,Jquery,Html,Css,我对Jquery非常陌生,所以请不要误会我。 我有一些图像,当用户单击图像时,其不透明度应降低。当用户单击另一个图像时,应恢复其原始属性 regex替换和对其应用glass id是额外的更改。 当用户单击其他图像时,如何重置css值 这是我的Jquery代码 $("#list img").click(function () { $(this).css("opacity",".3"); var selectImgName = $(this).attr("src"); selectImgNam

我对Jquery非常陌生,所以请不要误会我。 我有一些图像,当用户单击图像时,其不透明度应降低。当用户单击另一个图像时,应恢复其原始属性

regex替换和对其应用glass id是额外的更改。 当用户单击其他图像时,如何重置css值

这是我的Jquery代码

$("#list img").click(function () {

$(this).css("opacity",".3");
var selectImgName =  $(this).attr("src");

selectImgName = selectImgName.replace("c", "b");

$("#glasses").attr("src", selectImgName);
    });
});
这是我的HTML代码

<div id="list"   >
<img src="img/c1.png" style="display:box; width:125px; margin-left:5px; margin-top:9px" />
<img src="img/c2.png" style="display:box; width:125px;margin-left:5px;margin-top:9px"/>
<img src="img/c3.png" style="display:box; width:125px;margin-left:5px;margin-top:9px" />    
<img src="img/c4.png" style="display:box; width:125px;margin-left:5px;margin-top:9px"/>
</div>

只需恢复所有图像的原始不透明度,然后更改单击的图像即可

$("#list img").click(function () {
    $("#list img").css("opacity", "1");
    $(this).css("opacity",".3");
});
这应该行得通。

类似这样的东西:

$("#list img").css("opacity","1"); //reset all
$(this).css("opacity",".3"); //set on clicked

如何将第一个(img/c1.png)图像的不透明度设置为默认的单击图像(不透明度=.3),然后应用上述代码。如何将第一个图像属性设置为默认的单击图像(不透明度=.3),然后进行相应的更改。因此,您单击图像,它会变得更加不透明?只需将CSS样式设置为.3,将其设置为默认值,然后交换上面代码中的值。您能帮助使用jsfiddleNo吗,我希望第一个图像的默认值为.3,当用户单击其他图像时,应将其更改为1。单击后,单击的图像将变为.3。我有另一个图像作为标题,这个孩子会影响到它。