自己积累的网页设计常用素材

来源:互联网 发布:怎么提高淘宝访客量 编辑:程序博客网 时间:2024/06/02 19:54

1.兼容ie8及以下的html5标签的js脚本

<!--[if lt IE 9]>   <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->

2.ie6浏览器提示升级

<script type="text/javascript">var ie6=!-[1,]&&!window.XMLHttpRequest;if(ie6){document.write('<div style="width:600px; margin:50px auto; border:1px #EEE solid; background:#f5f5f5; padding:30px;">');document.write('<p>亲爱的用户您好,我们检测到你目前使用的浏览器版本仍然是IE6,为了不影响你的正常使用,强烈建议您使用更优秀的浏览器<a href="http://www.google.cn/chrome/intl/zh-CN/landing_chrome.html" target="_blank">Chrome</a> 或者 <a href="http://firefox.com.cn/download/" target="_blank">Firefox</a> 浏览器。感谢您的理解。</p>');document.write('</div>');document.write('');}</script>

3.简易的AJAX代码

<script type="text/javascript">var url="http://localhost/1.php?id=*";var ajax=null;if(window.XMLHttpRequest){ajax=new XMLHttpRequest();}else if(window.ActiveXObject){ajax = new ActiveXObject("Microsoft.XMLHTTP");}else{//return;}ajax.open("GET",url,true);ajax.send(null);ajax.onreadystatechange=function(){if(ajax.readyState==4 && ajax.status==200){alert(ajax.responseText);}}</script>

4.浏览器3秒钟自动跳转代码

<script type="text/javascript">//1.页面无提示,3秒钟后跳转window.setTimeout("location.href='*.html'",3000);</script><script type="text/javascript"> //2.页面文字提示和时间倒计时,以及如果不跳转可以点击链接跳转function delayURL(url){var delay=document.getElementById("time").innerHTML;if(delay>0){delay--;document.getElementById("time").innerHTML=delay;}else{window.location.href=url;}setTimeout("delayURL('" + url + "')", 1000);}</script><span id="time" style="background: red">3</span> 秒钟之后自动跳转,如果不跳转,请点击下面链接<a href="*.html"></a><script type="text/javascript"> delayURL("*.html"); </script>

5.点击按钮运行页面中的html代码

<!doctype html><html><head><title>运行代码</title><meta http-equiv="content-type" content="text/html; charset=utf-8"><script>//获取一个对象function getByid(id) {if (document.getElementById) {return document.getElementById(id);} else if (document.all) {return document.all[id];} else {return null;}}function runCode(id){  //定义一个运行代码的函数,  var code=getByid(id).value;//即要运行的代码。  var newwin=window.open('','','');  //打开一个窗口并赋给变量newwin。  newwin.opener = null // 防止代码对脚本页面修改  newwin.document.write(code);  //向这个打开的窗口中写入代码code,这样就实现了运行代码功能。  newwin.document.close();}</script><textarea id="runcode" rows="9" cols="72" readonly="readonly"><script>alert("这是运行代码结果^_^")</script></textarea><br /><input onclick="runCode('runcode')" type="button" value="运行代码" /></body></html>

6.页脚固定底部(兼容IE6浏览器)

#footer {    position: fixed;    left: 0px;    bottom: 0px;    height: 30px;    width: 100%;    background: #444;}/* IE 6 */* html #footer {    position: absolute;    top: expression((0-(footer.offsetHeight)+(document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight)+(ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop))+'px');}