样式怎么设置,求高手指教
<a>1</a>
<a>2</a>
<a>3</a>
<a>4</a>
有几个 a 标签,当点击 1的时候,使A标签处于选中状态,点击 2时,2处于选中状态,其他标签未选中,
请教这个样式怎么设置?
[解决办法]
<script type="text/javascript">
window.onload = function(){
var _as = document.getElementsByTagName('a');
for(var i = 0 ; i < _as.length ; ++i){
_as[i].length = _as.length;
_as[i].onclick = function(){
for(var j = 0 ; j < this.length ; ++j){
_as[j].className='';
}
this.className = 'selected';
}
}
}
</script>
<style type="text/css">
a{
cursor: pointer;
}
.selected{
color:red;
}
</style>
<a>1</a>
<a>2</a>
<a>3</a>
<a>4</a>