用css写足矣,css中有focus这个神奇的东西,难道你没有用过吗,给你个例子吧
html:
<input type="text" placeholder="Enter Name." name="name" maxlength="300" class="input">css:
.input {border:0
padding:10px
font-size:1.3em
font-family:"Ubuntu Light","Ubuntu","Ubuntu Mono","Segoe Print","Segoe UI"
color:#ccc
border:solid 1px #ccc
margin:0 0 20px
width:300px
-moz-box-shadow: inset 0 0 4px rgba(0,0,0,0.2)
-webkit-box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.2)
box-shadow: inner 0 0 4px rgba(0, 0, 0, 0.2)
-webkit-border-radius: 3px
-moz-border-radius: 3px
border-radius: 3px
}
input:focus {
outline: none !important
border:1px solid red
box-shadow: 0 0 10px #719ECE
}
$(".XXX").click(function($(".XXX").removeClass(".current")
$(this).addClass(".current")
))
一般这样就能解决问题了
先点击你选择的,所有的.XXX的class 取消.current(class),然后给当前的div添加.XXX(class)