表单美化的js代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>单选按钮美化</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
#content{
width: 400px;
height: 32px;
border: 1px solid #DFDFDF;
margin: 50px auto 0;
font-size: 12px;
font-family: "微软雅黑";
}
#radio{
height: 32px;
line-height: 32px;
padding-left: 15px;
}
#radio dt{
float: left;
}
#radio dd{
float: left;
margin: 0 10px 0 8px;
padding-left: 23px;
position: relative;
}
#radio dd a{
text-decoration: none;
color: #000000;
}
#radio dd a:hover{
text-decoration: underline;
color: #CC0000;
}
#radio dd a:hover b{
background-position:-15px -118px;
}
#radio dd b{
display: block;
width: 20px;
height: 20px;
background: url(images/radiobutton.gif) no-repeat -15px -18px;
position: absolute;
top:8px;
left: 0;
}
#radio .selected b,#radio .selected a:hover b{
background-position:-15px -218px;
}
</style>
</head>
<body>
<div id="content">
<dl id="radio">
<dt>配送类型:</dt>
<dd class="selected"><a href="#"><b></b>全部</a></dd>
<dd><a href="#"><b></b>京东</a></dd>
<dd><a href="#"><b></b>第三方</a></dd>
</dl>
</div>
<script type="text/javascript">
window.onload=function(){
var oas=document.getElementsByTagName("a");
//alert(oas.length);
for(var i=0;i<oas.length;i++){
oas[i].onclick=function(){
for(var j=0;j<oas.length;j++){
oas[j].parentNode.className="";
}
oas[this].parentNode.className="selected";
}
}
}
</script>
</body>
</html>
我看到评论说这个思路与Tab一样,所以我就按照那个思路写的可是浏览器中最后一句报错,这种思路不可以吗?求大神解释