为了账号安全,请及时绑定邮箱和手机立即绑定

表单美化的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一样,所以我就按照那个思路写的可是浏览器中最后一句报错,这种思路不可以吗?求大神解释

正在回答

1 回答

这个方法可以的。 

你可以直接获取dd标签, var oDd=document.getElementsByTagName("dd");

直接清空其它class名, 

给 this.className='selected';    

不用.parentNode去找父级了。

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
表单美化
  • 参与学习       41172    人
  • 解答问题       151    个

本教程讲解表单美化,主要是对方法和思路的分享,让表单与众不同

进入课程

表单美化的js代码

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信