javascript 常用事件Word格式.docx
《javascript 常用事件Word格式.docx》由会员分享,可在线阅读,更多相关《javascript 常用事件Word格式.docx(42页珍藏版)》请在冰豆网上搜索。
取變數類型
typeof($js_libpath)=="
undefined"
下拉選單
下拉選單.options[索引]
下拉選單.options.length
搜尋對象
document.getElementsByName("
r1"
document.getElementById(id);
定時
timer=setInterval('
scrollwindow()'
delay);
clearInterval(timer);
UNCODE編碼
escape(),unescape
父對象
obj.parentElement(dhtml)
obj.parentNode(dom)
交換表的行
TableID.moveRow(2,1)
代換CSS
document.all.csss.href="
a.css"
;
並排顯示
display:
inline
隱藏焦點
hidefocus=true
根據寬度換行
style="
word-break:
break-all"
自動Reload
<
metaHTTP-EQUIV="
refresh"
CONTENT="
8;
URL="
>
簡單郵件
ahref="
mailto:
aaa@?
subject=ccc&
body=xxxyyy"
快速轉到位置
obj.scrollIntoView(true)
錨
aname="
first"
#first"
anchors<
/a>
網頁傳遞參數
location.search();
可編輯
obj.contenteditable=true
執行選單命令
obj.execCommand
雙字元字元
/[^\x00-\xff]/
漢字
/[\u4e00-\u9fa5]/
讓英文字元串超出表格寬度自動換行
word-wrap:
break-word;
word-break:
break-all;
透明背景
IFRAMEsrc="
1.htm"
width=300height=180allowtransparency>
/iframe>
獲得style內容
obj.style.cssText
HTML標籤
document.documentElement.innerHTML
第一個style標籤
document.styleSheets[0]
style標籤裡的第一個樣式
document.styleSheets[0].rules[0]
防止點選空連結時,頁面往往重置到頁首端
javascript:
function()"
word<
上一網頁源
asp:
request.servervariables("
HTTP_REFERER"
)
document.referrer
釋放內存
CollectGarbage();
禁止右鍵
document.oncontextmenu=function(){returnfalse;
}
禁止儲存
noscript>
iframesrc="
*.htm"
/noscript>
禁止選取
bodyoncontextmenu="
returnfalse"
ondragstart="
onselectstart="
onselect="
document.selection.empty()"
oncopy="
onbeforecopy="
onmouseup="
document.selection.empty()>
禁止貼上
inputtype=textonpaste="
地址欄圖標
linkrel="
ShortcutIcon"
href="
favicon.ico"
favicon.ico名字最好不變16*16的16色,放虛擬目錄根目錄下
收藏欄圖標
Bookmark"
檢視原始碼
inputtype=buttonvalue=檢視網頁源程式碼onclick="
window.location='
view-source:
+'
關閉輸入法
inputstyle="
ime-mode:
disabled"
自動全選
inputtype=textname=text1value="
123"
onfocus="
this.select()"
ENTER鍵可以讓游標移到下一個輸入框
inputonkeydown="
if(event.keyCode==13)event.keyCode=9"
文字框的預設值
inputtype=textvalue="
alert(this.defaultvalue)"
title換行
obj.title="
123sdfs"
獲得時間所代表的微秒
varn1=newDate("
2004-10-10"
.replace(/-/g,"
\/"
)).getTime()
視窗是否關閉
win.closed
checkbox扁平
inputtype=checkboxstyle="
position:
absolute;
clip:
rect(5px15px15px5px)"
br>
獲取選取內容
document.selection.createRange().duplicate().text
自動完成功能
inputtype=textautocomplete=on>
打開該功能
inputtype=textautocomplete=off>
關閉該功能
視窗最大化
bodyonload="
window.resizeTo(window.screen.width-4,window.screen.height-50);
window.moveTo(-4,-4)"
無關閉按鈕IE
windows.open("
aa.htm"
"
meizz"
fullscreen=7"
統一編碼/解碼
alert(decodeURIComponent(encodeURIComponent("
http:
//你好.com?
as=hehe"
)))
encodeURIComponent對"
:
"
、"
/"
和"
?
也編碼
表格行指示
tronmouseover="
this.bgColor='
#f0f0f0'
onmouseout="
#ffffff'
各種尺寸
s+="
\r\n網頁可見區域寬:
+document.body.clientWidth;
\r\n網頁可見區域高:
+document.body.clientHeight;
+document.body.offsetWeight+"
(包括邊線的寬)"
+document.body.offsetHeight+"
\r\n網頁正文全文寬:
+document.body.scrollWidth;
\r\n網頁正文全文高:
+document.body.scrollHeight;
\r\n網頁被捲去的高:
+document.body.scrollTop;
\r\n網頁被捲去的左:
+document.body.scrollLeft;
\r\n網頁正文部分上:
+window.screenTop;
\r\n網頁正文部分左:
+window.screenLeft;
\r\n螢幕分辨率的高:
+window.screen.height;
\r\n螢幕分辨率的寬:
+window.screen.width;
\r\n螢幕可用工作區高度:
+window.screen.availHeight;
\r\n螢幕可用工作區寬度:
+window.screen.availWidth;
過濾數字
inputtype=textonkeypress="
returnevent.keyCode>
=48&
&
event.keyCode<
=57||(this.value.indexOf('
.'
)<
0?
event.keyCode==46:
false)"
onpaste="
return!
clipboardData.getData('
text'
).match(/\D/)"
ondragenter="
特殊用途
inputtype=buttonvalue=匯入收藏夾onclick="
window.external.ImportExportFavorites(true,'
//localhost'
inputtype=buttonvalue=匯出收藏夾onclick="
window.external.ImportExportFavorites(false,'
inputtype=buttonvalue=整理收藏夾onclick="
window.external.ShowBrowserUI('
OrganizeFavorites'
null)"
inputtype=buttonvalue=語言設定onclick="
LanguageDialog'
inputtype=buttonvalue=加入收藏夾onclick="
window.external.AddFavorite('
'
google'
)"
inputtype=buttonvalue=加入到頻道onclick="
window.external.addChannel('
window.external.showBrowserUI('
PrivacySettings'
null)"
不快取
METAHTTP-EQUIV="
pragma"
no-cache"
Cache-Control"
no-cache,must-revalidate"
expires"
0"
正則匹配
匹配中文字元的正則表達式:
[\u4e00-\u9fa5]
匹配雙字元字元(包括漢字在內):
[^\x00-\xff]
匹配空行的正則表達式:
\n[\s|]*\r
匹配HTML標記的正則表達式:
/<
(.*)>
.*<
\/\1>
|<
(.*)\/>
/
匹配首尾空格的正則表達式:
(^\s*)|(\s*$)(像vbscript那樣的trim函數)
匹配Email地址的正則表達式:
\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
匹配網址URL的正則表達式:
//([\w-]+\.)+[\w-]+(/[\w-./?
%&
=]*)?
以下是例子:
利用正則表達式限制網頁表單裡的文字框輸入內容:
用正則表達式限制只能輸入中文:
onkeyup="
value=value.replace(/[^\u4E00-\u9FA5]/g,'
onbeforepaste="
clipboardData.setData('
clipboardData.getData('
).replace(/[^\u4E00-\u9FA5]/g,'
))"
1.用正則表達式限制只能輸入全角字元:
onkeyup="
value=value.replace(/[^\uFF00-\uFFFF]/g,'
).replace(/[^\uFF00-\uFFFF]/g,'
2.用正則表達式限制只能輸入數字:
value=value.replace(/[^\d]/g,'
)"
onbeforepaste="
).replace(/[^\d]/g,'
3.用正則表達式限制只能輸入數字和英文:
value=value.replace(/[\W]/g,'
消除圖像工具欄
IMGSRC="
mypicture.jpg"
HEIGHT="
100px"
WIDTH="
GALLERYIMG="
false"
or
head>
metahttp-equiv="
imagetoolbar"
content="
no"
/head>
無提示關閉
functionClose()
{
varua=navigator.userAgent
varie=navigator.appName=="
MicrosoftInternetExplorer"
true:
false
if(ie)
varIEversion=parseFloat(ua.substring(ua.indexOf("
MSIE"
)+5,ua.indexOf("
ua.indexOf("
))))
if(IEversion<
5.5)
varstr='
objectid=noTipCloseclassid="
clsid:
ADB880A6-D8FF-11CF-9377-00AA003B7A11"
str+='
paramname="
Command"
value="
Close"
/object>
document.body.insertAdjacentHTML("
beforeEnd"
str);
document.all.noTipClose.Click();
else
windows.opener=null;
window.close();
window.close()
取得控件得絕對位置
(1)
scriptlanguage="
javascript"
functiongetoffset(e)
vart=e.offsetTop;
varl=e.offsetLeft;
while(e=e.offsetParent)
t+=e.offsetTop;
l+=e.offsetLeft;
varrec=newArray
(1);
rec[0]=t;
rec[1]=l;
returnrec
/script>
獲得控件的絕對位置
(2)
oRect=obj.getBoundingClientRect();
oRect.left
oRect.
最小化,最大化,關閉
objectid=minclassid="
Minimize"
objectid=maxclassid="
Maximize"
OBJECTid=closeclassid="
adb880a6-d8ff-11cf-9377-00aa003b7a11"
PARAMNAME="
/OBJECT>
inputtype=buttonvalue=最小化onclick=min.Click()>
inputtype=buttonvalue=最大化onclick=max.Click()>
inputtype=buttonvalue=關閉onclick=close.Click()>
游標停在文字最後
functioncc()
vare=event.srcElement;
varr=e.createTextRange();
r.moveStart('
character'
e.value.length);
r.collapse(true);
r.select();
cc()"
頁面進入和登出的特效
進入頁面<
Page-Enter"
revealTrans(duration=x,transition=y)"
推出頁面<
Page-Exit"
這個是頁面被載入和調出時的一些特效。
duration表示特效的持續時間,以秒為單位。
transition表示使
用哪種特效,取值為1-23:
0矩形縮小
1矩形擴大
2圓形縮小
3圓形擴大
4下到上Reload
5上到下Reload
6左到右Reload
7右到左Reload
8豎百葉窗
9橫百葉窗
10錯位橫百葉窗
11錯位豎百葉窗
12點擴散
13左右到中間Reload
14中間到左右Reload
15中間到上下
16上下到中間
17右下到左上
18右上到左下
19左上到右下
20左下到右上
21橫條
22豎條
23
網頁是否被檢索
metaname="
ROBOTS"
屬性值"
其中屬性值有以下一些:
屬性值為"
all"
檔案將被檢索,且頁上連結可被查詢;
none"
檔案不被檢索,而且不查詢頁上的連結;
index"
檔案將被檢索;
follow"
查詢頁上的連結;
noindex"
檔案不檢索,但可被查詢連結;
nofollow"
列印分頁
pstyle="
page-break-after:
always"
page1<
/p>
page2<
設定列印
objectid="
factory"
style="
viewastext
classid="
1663ed61-23eb-11d2-b92f-008048fdd814"
codebase="
inputtype=buttonvalue=頁面設定onclick="
factory.printing.PageSetup()"
inputtype=buttonvalue=列印預覽onclick="
factory.printing.Preview()"
scriptlanguage=javascript>
functionwindow.onload()
//--advancedfeatures
factory.printing.SetMarginMeasure
(2)//measuremarginsininches
factory.printing.SetPageRange(false,1,3)//needpagesfrom1to3
factory.printing.printer="