实用代码片段

1.设为首页 收藏本站
<a href=# onclick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.makewing.com/');">设为首页</a>
<a href="javascript:window.external.AddFavorite('http://www.makewing.com/','懒人图库')">收藏本站</a>
----------------------------------------------------------------------------------------------------------------------------------
2.select跳转菜单新窗口
<select onchange="window.open(this.options[this.selectedIndex].value)" name="select">
<option value="http://www.microsoft.com/ie" selected="selected">Internet Explorer</option>
<option value="http://www.microsoft.com">Microsoft Home</option>
<option value="http://msdn.microsoft.com">Developer Network</option>
</select>
-----------------------------------------------------------------------------------------------------------------------------
3.通过样式改变网页颜色
<link id="cssChange" href="style.css" rel="stylesheet" type="text/css" />
<script>
function setSkin(n)
 {
 var css = document.getElementById("cssChange");
 var cssList=new Array("yellow.css","red.css","green.css","blue.css","purple.css");
 var cssurl = "";
 cssurl +=cssList[n];
 css.href=cssurl;
 }
</script>
<div> <img src="yellow.jpg" onclick=setSkin(0) />
<img src="red.jpg" onclick=setSkin(1) />
<img src="green.jpg" onclick=setSkin(2) />
<img src="blue.jpg" onclick=setSkin(3) />
<img src="purple.jpg" onclick=setSkin(4) /></div>
----------------------------------------------------------------------------------------------------------------------------------
4.字号缩放
<script>
function DoZoom(size)
{
document.getElementById('Zoom').style.fontSize=size+"px";
}
</script>
<span id="Zoom">需要缩放的字体<a herf="javascript:DoZoom(16)">大</a><a herf="javascript:DoZoom(14)">中</a ><a herf="javascript:DoZoom(12)">小</a</span>
----------------------------------------------------------------------------------------------------------------------------------
5.不能点右键、不用CTRL+A、不能复制
<body oncontextmenu="window.event.returnValue=false"
onkeypress="window.event.returnValue=false"
onkeydown="window.event.returnValue=false"
onkeyup="window.event.returnValue=false"
ondragstart="window.event.returnValue=false"
onselectstart="event.returnValue=false">
</body>
试试鼠标右键,试试CTRL+A全选,试试鼠标拖选复制?
----------------------------------------------------------------------------------------------------------------------------------
6.三个常用的js时间特效
<script language=JavaScript>
<!--
var enabled = 0; today = new Date();
var day; var date;
if(today.getDay()==0) day = " 星期日"
if(today.getDay()==1) day = " 星期一"
if(today.getDay()==2) day = " 星期二"
if(today.getDay()==3) day = " 星期三"
if(today.getDay()==4) day = " 星期四"
if(today.getDay()==5) day = " 星期五"
if(today.getDay()==6) day = " 星期六"
document.fgColor = "000000";
date = "今天是:" + (today.getYear()) + "年" + (today.getMonth() + 1 ) + "月" + today.getDate() + "日" + day +"";
document.write(date);
// -->
</script>今天是:2009年5月26日 星期二 
 
<div id="webjx"></div>
<script>setInterval("webjx.innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());",1000);
   </script>
2009年5月26日 星期二 11:26:49 星期二
<span id=nowDate></span>
 <span id=nowTime></span>
    <script><!--
var ns4up1 = (document.layers) ? 1 : 0;  // browser sniffer
var ie4up1 = (document.all&&(navigator.appVersion.indexOf("MSIE 4") == -1)) ? 1 : 0;
var ns6up1 = (document.getElementById&&!document.all) ? 1 : 0;
function nowclock() {
if (!ns4up1 && !ie4up1 && !ns6up1) return false;
var digital = new Date();
var hours = digital.getHours();
var minutes = digital.getMinutes();
var seconds = digital.getSeconds();
var day = digital.getDate();
var month = digital.getMonth() + 1;
var year = digital.getYear();
var amOrPm = "AM";
if (hours > 11) amOrPm = "PM";
if (hours > 12) hours = hours - 12;
if (hours == 0) hours = 12;
if (minutes < 10) minutes = "0" + minutes;
if (seconds < 10) seconds = "0" + seconds;
if (day < 10) day = "0" + day;
if (month < 10) month = "0" + month;
dispTime = hours + ":" + minutes + ":" + seconds + " " + amOrPm;
dispDate = year + "年" + month + "月" + day+ "日, " ;
if (ns4up1) {
document.layers.nowTime.document.write(dispTime);
document.layers.nowTime.document.close();
document.layers.nowDate.document.write(dispDate);
document.layers.nowDate.document.close();
} else if (ns6up1){
document.getElementById("nowTime").innerHTML = dispTime;
document.getElementById("nowDate").innerHTML = dispDate;
} else if (ie4up1){
nowTime.innerHTML = dispTime;
nowDate.innerHTML = dispDate;
} setTimeout("nowclock()", 1000);
} nowclock();
//-->
 </script>2009年05月26日, 11:29:21 AM
----------------------------------------------------------------------------------------------------------------------------------
7.css凹陷字体
<div width:300px;padding:20px;overflow:hidden;word-wrap:break-word;word-break:break:all; font-size:12px; line-height:18px; background-color:#eeeeee;"></div>
<font disabled>
怎么样,我凹下去了吧?<br>
你不想试试吗?<br></font>

你可能感兴趣的:(JavaScript,css,Microsoft,IE)