在JS中如何实现点击图片进去出现边框???

在JS中如何实现点击图片进去出现边框???,第1张

可以借助JS来实现,请参考天南写的DEMO:

<img src="aa.jpg" width="160" height="160" onclick="this.style.border='solid 1px #F39'" />

使用:.addClass('active').siblings().removeClass('active');即可

解释:给当前选中的增加边框.addClass('active')

给原先选中的取消边框.siblings().removeClass('active')

详细如下:

<style type="text/css">

.clr:after{clear:bothdisplay:blockoverflow:hiddenheight:0content:"."}

.clr{zoom:1}

.price{width:100%}

.price a{width:100pxheight:40pxline-height:40pxtext-align:centerbackground:#eeefloat:leftmargin:0 5pxdisplay:blockcursor:pointer}

.price a.active{border:1px solid red}

</style>

<div class="price clr">

<a>5元</a>

<a>10元</a>

<a>100元</a>

<a>200元</a>

</div>

<script type="text/javascript" src="引用jquery.js或zepto.js"></script>

<script type="text/javascript">

$(function(){

$('.price a').click(function(){

$(this).addClass('active').siblings().removeClass('active')

})

})

</script>

效果如下:

建议自己写看看 触发click事情后复制 图片这一层的代码 增加到 那个框里面

.clone() 这个是复制增加.append() 希望对你有点帮助。。!!!


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11762750.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-18
下一篇2023-05-18

发表评论

登录后才能评论

评论列表(0条)

    保存