<img src="http://www.csdn.net/Images/logo_csdn.gif" id="ice"/>
<script language="javascript">
<!--
img = ["http://www.csdn.net/Images/logo_csdn.gif",
"http://zi.csdn.net/120_63.gif",
"http://zi.csdn.net/comm_button.gif",
"http://zi.csdn.net/1.gif"
];
current = 0;
document.getElementById("ice").onclick=function(){
if(current == img.length-1)
current = 0;
else
current++;
this.src=img[current];
}
//-->
</script>

解决方案 »

  1.   

    <script type="text/javascript">
      //<![CDATA[
    function foo(o) {
      var p = [
        "http://zi.csdn.net/community_post_page-vertical_banner120x360.gif",
        "http://zi.csdn.net/comm_button.gif",
        "http://zi.csdn.net/autodesk2-760_91.gif"];
      var x=o.getAttribute("cnt"); var a=o.getAttribute("cnt");
      if (parseInt(a)==p.length-1) return;
      a ? new function() {
        eval('o.src=p['+(parseInt(++a))+']');
        o.setAttribute("cnt",a);
      }: new function() {
        o.src = p[0];
        o.setAttribute("cnt", "0");
      }
    }
      //]]>
      </script>
      <body id="www.never-online.net">
      <img src="http://www.csdn.net/Images/logo_csdn.gif" onclick="foo(this)"/>
      </body>
      

  2.   

    function foo(o) {
      var p = [
        "http://zi.csdn.net/community_post_page-vertical_banner120x360.gif",
        "http://zi.csdn.net/comm_button.gif",
        "http://zi.csdn.net/autodesk2-760_91.gif"];
       if (window.cnt==p.length) return;
       window.cnt?o.src=p[cnt++]:new function(){window.cnt=1;o.src=p[0];};
    }
      

  3.   

    准备好三张图片放在同一目录下面,
    并取名为image1.gif,image2.gif,image3.gif//<script language="jscript">

    function changeIt()
    {
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var node = document.getElementById("image");
    var src = node.getAttribute("src");
    var imageName = fso.GetBaseName(src);
    if (imageName == "image1")
    {
    node.setAttribute("src","./image/image2.gif");
    }
    else if (imageName == "image2")
    {
    node.setAttribute("src","./image/image3.gif");
    }
    else if (imageName == "image3")
    {
    node.setAttribute("src","./image/image1.gif");
    }
    else
    {
    node.setAttribute("src","./image/image1.gif");
    }
    }
    </script>
    </HEAD><BODY>
    <button onclick="changeIt();return true;">更换图片</button>
    <img id="image" src="./image/image1.gif">
    </BODY>
    </HTML>
      

  4.   

    更正一下,下面的是javascript<script language="javascriptscript">

    function changeIt()
    {
    var node = document.getElementById("image");
    var src = node.getAttribute("src");
    var pos = src.lastIndexOf('/');//取图片名较JS多了一步
    var imageName = src.substr(pos+1, src.length-pos);//取图片名较JS多了一步
    if (imageName == "image1.gif")
    {
    node.setAttribute("src","./image/image2.gif");
    }
    else if (imageName == "image2.gif")
    {
    node.setAttribute("src","./image/image3.gif");
    }
    else if (imageName == "image3.gif")
    {
    node.setAttribute("src","./image/image1.gif");
    }
    }
    </script>
    </HEAD><BODY>
    <button onclick="changeIt();return true;">更换图片</button><br/>
    <img id="image" src="./image/image1.gif">
    </BODY>
    </HTML>
      

  5.   

    楼上的怎么这么多代码?
    <img src="http://www.csdn.net/Images/logo_csdn.gif" onclick="foo(this)"/>
    <script type="text/javascript">
    //<![CDATA[
    function foo(o) {
      var p = [
        "http://zi.csdn.net/community_post_page-vertical_banner120x360.gif",
        "http://zi.csdn.net/comm_button.gif",
        "http://zi.csdn.net/autodesk2-760_91.gif"];
       if (window.cnt==p.length) return;
       window.cnt?o.src=p[cnt++]:new function(){window.cnt=1;o.src=p[0];};
    }
    //]]>
    </script>
      

  6.   

    谢谢!但是,很多个 <img src="http://www.csdn.net/Images/logo_csdn.gif" id="ice"/> 怎么办呢?
      

  7.   

    只有第一楼的可以用
    但是,很多个 <img src="http://www.csdn.net/Images/logo_csdn.gif" id="ice"/> 怎么办呢
      

  8.   

    加到数组里就可以了...我还以为不循环呢...加到p数组里
    <img src="http://www.csdn.net/Images/logo_csdn.gif" onclick="foo(this)"/>
    <script type="text/javascript">
    //<![CDATA[
    function foo(o) {
      var p = [
        "http://zi.csdn.net/community_post_page-vertical_banner120x360.gif",
        "http://zi.csdn.net/comm_button.gif",
        "http://zi.csdn.net/autodesk2-760_91.gif"];
       if (window.cnt==p.length) cnt=0;
       window.cnt?o.src=p[cnt++]:new function(){window.cnt=1;o.src=p[0];};
    }
    //]]>
    </script>
      

  9.   

    谢谢 我想问的是如果 网页里 有很多 logo_csdn.gif 这样 的同样的图片呢?该怎么办
      

  10.   

    <img src="http://zi.csdn.net/comm_button.gif" onclick="foo(this)"/>
    <script type="text/javascript">
    //<![CDATA[
    var idx=1; // 初始值,如果没有就设为0或者注释掉
    var cnt = idx||0;
    function foo(o) {
      var p = [
        "http://zi.csdn.net/community_post_page-vertical_banner120x360.gif",
        "http://zi.csdn.net/comm_button.gif",
        "http://zi.csdn.net/autodesk2-760_91.gif"];
      o.src=p[++cnt==p.length?cnt=0:cnt];
    }
    //]]>
    </script>
      

  11.   

    现在我想到了一个方法:但是 还有不足的地方,就是 我打印出 图片的 src属性是这样的 
    file:///D:/liyanming/img/img/checkboxon.gif 不知道 还有没有 别的方法判断呢?或者怎样
    获得 图片的 相对路径呢 ?请指教,谢谢大家了,下面是我的代码?function changepic(o){
      //if (document.dd.)
    if (o.src=="file:///D:/liyanming/img/img/checkboxon.gif")
    o.src= 'img/img/checkboxno.gif';
    else if (o.src=="file:///D:/liyanming/img/img/checkboxno.gif")
    o.src= 'img/img/checkboxoff.gif';
    else
    o.src= 'img/img/checkboxon.gif';
    }
      

  12.   

    foo中的src参数为图片地址,如果数组中的地址与之相同,那么自动从该下标开始记数<img src="http://zi.csdn.net/autodesk2-760_91.gif" onclick="foo(this,this.src)"/>
    <script type="text/javascript">
    //&lt;![CDATA[var cnt = 0;
    function foo(o,src) {
      var p = [
        "http://zi.csdn.net/community_post_page-vertical_banner120x360.gif",
        "http://zi.csdn.net/comm_button.gif",
        "http://zi.csdn.net/autodesk2-760_91.gif"];
      if (!o.getAttribute("x")) {
        for (var i=0; i<p.length; i++) 
        if (p[i]==src) cnt=i;
      }
      o.src=p[++cnt==p.length?cnt=0:cnt];
    }
    //]]&gt;
    </script>
      

  13.   

    BlueDestiny(这回真的准备要改名字了...) ( 两星(中级)) 信誉:100  2006-7-27 13:59:09  得分:0
    ?  楼上的怎么这么多代码?呵,写到一行也行,##