首页 新闻 赞助 找找看

a 标签点击后改变样式,点击其他a时样式还原,怎么也弄不出来??

0
悬赏园豆:20 [待解决问题]

现在只是鼠标滑过时显示,点击后没反应,点击其他a标签时要实现首页a恢复原有状态

代码如下:

<div class="lead">
      <ul>
  <li class="title1"><a id="home" href="Welcome.aspx" target="_parent" runat="server" onmouseup="ChangeClass()">首页</a></li>
        <li class="title2"><a id="zs" href="textList.aspx" target="_parent" onmouseup="ChangeClass2()">展示</a></li>
      </ul>
   </div>

script代码:

 <script type="text/javascript">
        function ChangeClass() {
            var a = document.getElementById("home");
            a.setAttribute("style", "width:118px; height:50px; text-decoration:none; color:#fff; background:url(images/titleback_yes1.png); background-repeat:no-repeat;");
        }
        function ChangeClass2() {
            var a = document.getElementById("zs");
            a.setAttribute("style", "width:118px; height:50px; text-decoration:none; color:#fff; background:url(images/titleback_yes2.png); background-repeat:no-repeat;");

style.css


        }
        }

    </script>

 

style.css

.title1 a{
    width:118px;
 height:50px;
 color:#333;
 line-height:50px;
 text-align:center;
 display:block;
 float:left;
 text-decoration:none;
 background: url(../images/titleback1.png);
 background-repeat:no-repeat;
 margin-right:-14px;
}
 style.css
.title1 a:active {width:118px; height:50px; text-decoration:blink; color:#fff; background:url(../images/titleback_yes1.png); background-repeat:no-repeat;}
.title1 a:hover {width:118px; height:50px; text-decoration:none; color:#fff; background:url(../images/titleback_yes1.png); background-repeat:no-repeat;}

lijunmomo的主页 lijunmomo | 初学一级 | 园豆:34
提问于:2014-07-05 16:21
< >
分享
所有回答(2)
0

两种样式:点击如果有A样式切换成B样式,如果有B样式切换成A样式,亲。

我想啸天 | 园豆:79 (初学一级) | 2014-07-05 16:26

不明白啊,你就说说我怎么改吧?谢啦

支持(0) 反对(0) lijunmomo | 园豆:34 (初学一级) | 2014-07-05 16:35

@lijunmomo: 静态页面发给我,我看看

支持(0) 反对(0) 我想啸天 | 园豆:79 (初学一级) | 2014-07-10 17:50

这样太繁琐了吧,

如果是10个这样的a标签你如何去做呢,而且点击完之后会跳到一个新的页面

 

支持(0) 反对(0) 书羽 | 园豆:200 (初学一级) | 2018-04-25 11:04
0

我先问一下,你发的这个代码就是你现在用的代码对吗?如果是的话,那么你这里多了一个还有你的style.css是想干嘛?。

<script type="text/javascript">
        function ChangeClass() {
            var a = document.getElementById("home");
            a.setAttribute("style", "width:118px; height:50px; text-decoration:none; color:#fff; background:url(images/titleback_yes1.png); background-repeat:no-repeat;");
        }
        function ChangeClass2() {
            var a = document.getElementById("zs");
            a.setAttribute("style", "width:118px; height:50px; text-decoration:none; color:#fff; background:url(images/titleback_yes2.png); background-repeat:no-repeat;");

style.css


        }
        }

    </script>

晓菜鸟 | 园豆:2594 (老鸟四级) | 2014-07-10 18:50
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册