使用:.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>
效果如下:
<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
function set() {
var a = document.getElementById("sss")
var d = document.createElement("br")
var c =a.cloneNode(false)
c.setAttribute("type","text")
var b = document.getElementById("body")
b.appendChild(d)
b.appendChild(c)
}
window.onload=function () {
document.getElementById("aaa").onclick=set
}
</script>
</head>
<body id="body">
<input type="text" id="sss">
<input type="button" id="aaa" value="添加">
</body>
</html
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)