由胖变瘦再由瘦变胖来回循环:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script type="text/javascript"> function func(){ var img=document.getElementById("ad"); //img.src="2.jpg"; var str=img.src; //alert(img.src); //alert(img.src.indexOf("1.jpg")); if(str.indexOf("1.jpg")>=0){ img.src="2.jpg"; }else{ img.src="1.jpg"; } } </script> </head> <body> <span><img src="1.jpg" id="ad"></span> <button onClick="func()">点击变瘦</button> </body> </html>
运行结果:
点击变瘦:
再点击变瘦就又回到开始的样子以此循环
原文:http://www.cnblogs.com/zyn0216/p/7507890.html