JS改变DIV背景图片 本帖最后由 zy370127267 于 2010-05-13 21:10:52 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html> <head> <title> New Document </title> </head> <body><div id="Image_09" style="width:200px;height:200px;"></div><div id="Image_10"> <div id="$1001" > <input type="button" value="变换背景图片" onClick="changePic();"> <script type="text/javascript"> var imgpath=["images/PS02.jpg","images/PS03.jpg","images/PS04.jpg"]; var index = 0; function changePic(){ index = index < imgpath.length ? index : 0; document.getElementById("Image_09").style.background = "url(" + imgpath[index] + ")"; index++; } </script></div> </body></html> var i=0;function changePic(){if(i==0){ document.getElementById("Image_09").style.background-image="images/PS02.jpg"; i++; }if(i==1){ document.getElementById("Image_09").style.background-image="images/PS03.jpg"; i++; }if(i==2){ document.getElementById("Image_09").style.background-image="images/PS04.jpg"; i=0; }} <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title><style type="text/css">#Image_09 {width:100%;height:500px;}</style></head><body><div id="Image_09"></div><div id="Image_10"> <input type="button" value="变换背景图片" onClick="changePic();"></div><script type="text/javascript">//<![CDATA[var i=0;var imgList=["images/PS02.jpg","images/PS03.jpg","images/PS04.jpg"];function changePic(){ var $o=document.getElementById('Image_09'); if(i>=imgList.length){i=0}; $o.style.background='url('+imgList[i++]+')';}//]]></script></body></html> 请问<%都是什么意思,我是初学者,不明白 如何在输入数据时碰到半角逗号就自动替换成全角逗号呢? 感觉没问题但就是运行不对的代码,请兄弟们看看 如何刷新iframe里的内容? 身份证效验的正则表达式,急,在线等! 一个网页中有两个form,其中一个在进第提交前的检查时,另一个也跟着检查了,这是怎么回事?? 能不能实现这样的输入?! 能不能说说正则表达式的规则 ModalDialog刷新父页面 我想在网页里插入flash文件,有办法能让它按照实际大小显示吗,谢谢. jquery取值问题 js中跨窗口传值传不过去
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
</head> <body>
<div id="Image_09" style="width:200px;height:200px;"></div>
<div id="Image_10">
<div id="$1001" >
<input type="button" value="变换背景图片" onClick="changePic();">
<script type="text/javascript">
var imgpath=["images/PS02.jpg","images/PS03.jpg","images/PS04.jpg"];
var index = 0;
function changePic(){
index = index < imgpath.length ? index : 0;
document.getElementById("Image_09").style.background = "url(" + imgpath[index] + ")";
index++;
}
</script>
</div>
</body>
</html>
var i=0;
function changePic(){
if(i==0){
document.getElementById("Image_09").style.background-image="images/PS02.jpg";
i++;
}
if(i==1){
document.getElementById("Image_09").style.background-image="images/PS03.jpg";
i++;
}
if(i==2){
document.getElementById("Image_09").style.background-image="images/PS04.jpg";
i=0;
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
#Image_09 {width:100%;height:500px;}</style>
</head><body>
<div id="Image_09"></div>
<div id="Image_10">
<input type="button" value="变换背景图片" onClick="changePic();">
</div>
<script type="text/javascript">
//<![CDATA[
var i=0;
var imgList=["images/PS02.jpg","images/PS03.jpg","images/PS04.jpg"];
function changePic(){
var $o=document.getElementById('Image_09');
if(i>=imgList.length){i=0};
$o.style.background='url('+imgList[i++]+')';
}
//]]>
</script>
</body>
</html>