Loading... **通过代码实现网页每次展示图片都不一样。** 侵删转自:[哈密站长网](http://www.0902zz.com/html/jc/asp/2018/0818/95429.html) > Java Script实现的图片随机切换代码,即每次刷新网页显示不同的图片,大家也许见过这样的特效,运行用了JavaScript中的时间函数now.getSeconds()编写而成,并非是使用了Random随机函数,供大家参考和学习。 **示例代码:** ``` <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>图片随机切换代码演示</title> </head> <BODY> <script language="JavaScript"> var VeryHuo = 5 var now = new Date() var sec = now.getSeconds() var ad = sec % VeryHuo; ad +=1; if (ad==1){ url="#"; alt="ad1"; banner="/uploads/common/images/wall1.jpg"; width="440"; height="230"; } if (ad==2) { url="#"; alt="ad2"; banner="/uploads/common/images/wall2.jpg"; width="440"; height="230"; } if (ad==3) { url="#"; alt="ad3"; banner="/uploads/common/images/wall3.jpg"; width="440"; height="230"; } if (ad==4) { url="#"; alt="ad4"; banner="/uploads/common/images/wall4.jpg"; width="440"; height="230"; } if (ad==5) { url="#"; alt="ad5"; banner="/uploads/common/images/wall5.jpg"; width="440"; height="230"; } document.write('<center>'); document.write('<a href=\"' + url + '\" target=\"_blank\">'); document.write('<img src=\"' + banner + '\" width=') document.write(width + ' height=' + height + ' '); document.write('alt=\"' + alt + '\" border=0><br>'); document.write('</center>'); --></script> <br /><br /><br /> Veryhuo.COM提示:刷新一下看看! </BODY> </HTML><div style="text-align:center;margin:30px 0 0 0;"><hr style="color:#999;height:1px;">如不能显示效果,请按Ctrl+F5刷新本页,更多网页代码:<a href='http://www.veryhuo.com/' target='_blank'>http://www.veryhuo.com/</a></div> ``` # 右侧搜索框随机图片 ``` <div id="AD1"> <div id="float" class="float"> <section id="custom_html-4" class="widget_text widget widget_custom_html"> <form action="https://www.baidu.com/s?" target="_blank" id="tsf" method="GET" autocomplete="off"> <input type="text" x-webkit-speech="" onfocus="if (this.value == '百度搜 输入内容 回车搜') {this.value = '';}" onblur="if (this.value == '') {this.value = '百度搜 输入内容 回车搜';}" value="百度搜 输入内容 回车搜" name="q1" "="" /> </form> <br/> <form action="https://weixin.sogou.com/weixin?" target="_blank" id="tsf" method="GET" autocomplete="off"> <input type="text" x-webkit-speech="" onfocus="if (this.value == '搜微信 输入内容 回车搜') {this.value = '';}" onblur="if (this.value == '') {this.value = '搜微信 输入内容 回车搜';}" value="搜微信 输入内容 回车搜" name="query" "="" /> </form> <br/> <form action="https://s.weibo.com/weibo?" target="_blank" id="tsf" method="GET" autocomplete="off"> <input type="text" x-webkit-speech="" onfocus="if (this.value == '搜微博 输入内容 回车搜') {this.value = '';}" onblur="if (this.value == '') {this.value = '搜微博 输入内容 回车搜';}" value="搜微博 输入内容 回车搜" name="q" "="" /> </form> <br/> <form action="https://v.sogou.com/v?" target="_blank" id="tsf" method="GET" autocomplete="off"> <input type="text" x-webkit-speech="" onfocus="if (this.value == '搜视频 输入内容 回车搜') {this.value = '';}" onblur="if (this.value == '') {this.value = '搜视频 输入内容 回车搜';}" value="搜视频 输入内容 回车搜" name="query" "="" /> </form> <br/> <form action="https://biz.finance.sina.com.cn/suggest/lookup_n.php?" target="_blank" id="tsf" method="GET" autocomplete="off"> <input type="text" x-webkit-speech="" onfocus="if (this.value == '搜股票 输入内容 回车搜') {this.value = '';}" onblur="if (this.value == '') {this.value = '搜股票 输入内容 回车搜';}" value="搜股票 输入内容 回车搜" name="q" "="" /> </form> <br/> <form action="https://www.qichacha.com/search?" target="_blank" id="tsf" method="GET" autocomplete="off"> <input type="text" x-webkit-speech="" onfocus="if (this.value == '搜企业 输入内容 回车搜') {this.value = '';}" onblur="if (this.value == '') {this.value = '搜企业 输入内容 回车搜';}" value="搜企业 输入内容 回车搜" name="key" "="" /> </form> <br/> <div style="text-align:center;margin-bottom:-3px;"> <script language="JavaScript"> var VeryHuo = 5 var now = new Date() var sec = now.getSeconds() var ad = sec % VeryHuo; ad +=1; if (ad==1){ url="http://cpuck.com/cs/"; alt="ad1"; banner="http://cpuck.com/wxm/img/tmcs233.png"; width="100%"; height="100%"; } if (ad==2) { url="http://cpuck.com/ly"; alt="ad2"; banner="http://cpuck.com/wxm/img/tc.png"; width="100%"; height="100%"; } if (ad==3) { url="http://cpuck.com/hc"; alt="ad3"; banner="http://cpuck.com/wxm/img/dy12306.png"; width="100%"; height="100%"; } if (ad==4) { url="http://cpuck.com/book/"; alt="ad4"; banner="http://cpuck.com/wxm/img/dybook.png"; width="100%"; height="100%"; } if (ad==5) { url="http://cpuck.com/alyf"; alt="ad5"; banner="http://cpuck.com/wxm/img/dyalyf.png"; width="100%"; height="100%"; } document.write('<center>'); document.write('<a href=\"' + url + '\" target=\"_blank\">'); document.write('<img src=\"' + banner + '\" width=') document.write(width + ' height=' + height + ' '); document.write('alt=\"' + alt + '\" border=0><br>'); document.write('</center>'); </script> </div> </section> </div> </div> ``` 最后修改:2024 年 10 月 07 日 © 允许规范转载 赞 如果觉得我的文章对你有用,请随意赞赏