简体   繁体   English

选中此复选框时,使用CSS和/或jQuery将带边框的父DIV包装起来

[英]On checkbox checked, wrap a parent DIV with a border using css and/or jQuery

I hope someone could help me with the following. 我希望有人可以在以下方面为我提供帮助。

If a user checks checkbox1 then a border (border: 1px solid green;) is added to the DIV SmallSquarePhoto using pure CSS or a combination of CSS and jQuery. 如果用户选中checkbox1,则使用纯CSS或CSS和jQuery的组合将边框(边框:1像素的纯绿色;)添加到DIV SmallSquarePhoto中。 Otherwise checkbox1 has a transparent color (border: 4px solid transparent;). 否则,checkbox1具有透明颜色(边框:4px纯透明;)。 Any help would be appreciated...Thanks 任何帮助将不胜感激...谢谢

<div id="SmallSquarePhoto" class="SmallSquarePhoto" style="background-image: url(/Members/images/background/<%# Eval("BG_fileName") %>)">
<div class="SmallSquarePhoto-content-wrapper"><div class="SmallSquarePhoto-content-inner">
<input id="checkbox1" name="BG_list" type="checkbox" runat="server" value='<%# Eval("BG_fileName") %>' />
</div></div></div>

JS JS

$('#checkbox1').on('click', function () {
    $('#SmallSquarePhoto').toggleClass('green-border', $(this).is(':checked'));
});

CSS CSS

.green-border{
   border: 1px solid green;
}
#SmallSquarePhoto #checkbox1 {
    border: 4px solid transparent;
}
#SmallSquarePhoto.green-border {
    border: 1px solid green;
}
#SmallSquarePhoto.green-border #checkbox1 {
    border: 0; 
}

Fiddle: http://jsfiddle.net/y9chau9o/ 小提琴: http//jsfiddle.net/y9chau9o/

On clicking check box adding border, Demo 单击复选框添加边框, 演示

$('#checkbox1').click(function(){    
    $('#SmallSquarePhoto').toggleClass('green-border');
});

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

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