常用的JavaScript代碼(二),javascript代碼
文章來自“PHP100中文網”
獲得時間所代表的微秒
var n1 = new Date("2004-10-10".replace(/-/g, "\/")).getTime()
視窗是否關閉
win.closed
checkbox扁平
<input type=checkbox style="position: absolute; clip:rect(5px 15px 15px 5px)"><br>
擷取選中內容
document.selection.createRange().duplicate().text
自動完成功能
<input type=text autocomplete=on>開啟該功能
<input type=text autocomplete=off>關閉該功能
視窗最大化
<body onload="window.resizeTo(window.screen.width - 4,window.screen.height-50);window.moveTo(-4,-4)">
無關閉按鈕IE
window.open("aa.htm", "meizz", "fullscreen=7");
統一編碼/解碼
alert(decodeURIComponent(encodeURIComponent("http://你好.com?as= hehe")))
encodeURIComponent對":"、"/"、";" 和 "?"也編碼
表格行指示
<tr onmouseover="this.bgColor='#f0f0f0'" onmouseout="this.bgColor='#ffffff'">
1.文字框焦點問題
onBlur:當失去輸入焦點後產生該事件
onFocus:當輸入獲得焦點後,產生該檔案
Onchange:當文字值改變時,產生該事件
Onselect:當文字加亮後,產生該檔案
<input type="text" value="郭強" onfocus="if(value=='郭強') {value=''}" onblur="if
(value=='') {value='郭強'}">點擊時文字消失,失去焦點時文字再出現
2.網頁按鈕的特殊顏色
<input type=button name="Submit1" value="郭強" size=10 class=s02
style="background-color:rgb(235,207,22)">
3.滑鼠移入移出時顏色變化
<input type="submit" value="找吧" name="B1" onMouseOut=this.style.color="blue"
onMouseOver=this.style.color="red" class="button">
4.平面按鈕
<input type=submit value=訂閱 style="border:1px solid :#666666; height:17px; width:25pt; font-size:9pt;
BACKGROUND-COLOR: #E8E8FF; color:#666666" name="submit">
5.按鈕顏色變化
<input type=text name="nick" style="border:1px solid #666666; font-size:9pt; height:17px;
BACKGROUND-COLOR: #F4F4FF; color:#ff6600" size="15" maxlength="16">
6.平面輸入框
<input type="text" name="T1" size="20" style="border-style: solid; border-width: 1">
7.使視窗變成指定的大小
<script>
window.resizeTo(300,283);
</script>