日期:2014-05-16  浏览次数:20454 次

求教:链接点击改变菜单图片
求教:想实现以下两个效果
1、点击“菜单一”,菜单一背景图片变为1a.gif。点击“菜单二”,菜单二的背景图片变为2a.gif,同时菜单一变回去1a.gif。
<tr>
                        <td   > <a   href= "# "   class= "b "   background= "1.gif "> 菜单一 </a> </td>
                        <td   > <a   href= "# "   class= "b "   background= "2.gif "> 菜单二 </a> </td>
                        <td   > <a   href= "# "   class= "b "   background= "3.gif "> 菜单二 </a> </td>
  </tr>


2、下面的代码是点击后显示或者隐藏一个表格。我想在点击后同时改变1.gif为2.gif,再次点击后变回去1.gif。
<script   lanuage= "Javascript ">
function   turnit(ss)
{
if   (ss.style.display== "none ")  
    {ss.style.display= " ";
     
    }
else
    {ss.style.display= "none ";  

    }
}
</script>
<div   onclick= "turnit(Content); "   style= "CURSOR:   hand "   > <img   src= "1.gif "   width= "13 "   height= "13 "   /> 点击这里使下面的表格显示或隐藏 <div>            
            <table   width= "166 "   id= "Content "   style= "DISPLAY:   none;   border-collapse:collapse "   >
                <tr>  
                    <td> 隐藏或显示 </td>
                </tr>
            </table>
</div>

感谢各位

------解决方案--------------------
2. <img src= "1.gif " width= "13 " height= "13 " /> 加ID= "img1 "
<script lanuage= "Javascript ">
function turnit(ss)
{
if (ss.style.display== "none ")
{ss.style.display= " ";
document.getElementById( 'img1 ').src = '2.gif ';
}
else
{ss.style.display= "none ";

document.getElementById( 'img1 ').src = '1.gif ';
}
}
</script>
------解决方案--------------------
<html>
<head>
<meta http-equiv= "content-type " content= "type=text/html; charset=gb2312 ">
<style>
</style>
<script language= "JavaScript ">
var selectedMenu = null;
function onClickColor(obj){
if(selectedMenu != null || selectedMenu != undefined){

selectedMenu.style.background = selectedMenu.style.background.replace(/a/gi, " ");
}
selectedMenu = obj;
obj.style.background = selectedMenu.style.background.replace(/(\d+)\.gif/gi, "$1a.gif ");
}
</script>
</head>
<body>
<table width= "219 " border= "0 " cellspacing= "0 " cellpadding= "0 ">
<tr>