点击li标记中的<a>标记改变li背景图片怎样实现
<div class="nav">
<ul>
<li id="li1" class="dianji" onclick="changeBack(this,1)" ><a id="a1" href="Index.aspx">网站首页</a></li>
<li id="li2" onclick="changeBack(this,2)"><a id="a2" href="About.aspx">公司简介</a></li>
<li id="li3" onclick="changeBack(this,3)"><a href="NewsCenter.aspx">新闻动态</a></li>
<li id="li4" onclick="changeBack(this,4)"><a href="ProShow.aspx">产品展示</a></li>
<li id="li5" onclick="changeBack(this,5)"><a href="Message.aspx">在线留言</a></li>
<li id="li6" onclick="changeBack(this,6)"><a href="Contact.aspx">联系我们</a></li>
</ul>
</div>
这是一个菜单,要在点击链接的时候给点击的链接的li改变背景图片,相当于选中这个li,点击其他li时,让之前选中的那个li恢复原样,大家帮帮我,怎么做?谢谢了
<
div
class
=
"nav"
>
<
ul
id
=
"change"
>
<
li
id
=
"li1"
class
=
"dianji"
onclick
=
"changeBack(this)"
><
a
id
=
"a1"
>网站首页</
a
></
li
>
<
li
id
=
"li2"
onclick
=
"changeBack(this)"
><
a
id
=
"a2"
>公司简介</
a
></
li
>
<
li
id
=
"li3"
onclick
=
"changeBack(this)"
><
a
>新闻动态</
a
></
li
>
<
li
id
=
"li4"
onclick
=
"changeBack(this)"
><
a
>产品展示</
a
></
li
>
<
li
id
=
"li5"
onclick
=
"changeBack(this)"
><
a
>在线留言</
a
></
li
>
<
li
id
=
"li6"
onclick
=
"changeBack(this)"
><
a
>联系我们</
a
></
li
>
</
ul
>
</
div
>
function changeBack(obj){
for(var i=1;i<=6;i++){
document.getElementById("li"+i).style.backgroundImage="";
}
obj.style.backgroundImage="url(image/3.jpg)";
obj.style.backgroundRepeat="no-repeat"; //这里加一句 }
for(var i=1;i<=6;i++){
document.getElementById("li"+i).style.backgroundImage="";
}
obj.style.backgroundImage="url(image/3.jpg)";
obj.style.backgroundRepeat="no-repeat"; //这里加一句 }