<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>
<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>
//<![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>
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];};
}
并取名为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>
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>
<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>
但是,很多个 <img src="http://www.csdn.net/Images/logo_csdn.gif" id="ice"/> 怎么办呢
<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>
<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>
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';
}
<script type="text/javascript">
//<![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];
}
//]]>
</script>
? 楼上的怎么这么多代码?呵,写到一行也行,##