亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問板塊 發(fā)新帖
查看: 1155 | 回復(fù): 0
打印 上一主題 下一主題

js小技巧 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2011-12-20 09:48 |只看該作者 |倒序?yàn)g覽

每一項(xiàng)都是js中的小技巧,但十分的實(shí)用!
1.document.write(""); 輸出語句
2.JS中的注釋為//
3.傳統(tǒng)的HTML文檔順序是:document->html->(head,body)
4.一個(gè)瀏覽器窗口中的DOM順序是:window->(navigator,screen,history,location,document)
5.得到表單中元素的名稱和值:document.getElementById("表單中元素的ID號(hào)").name(或value)
6.一個(gè)小寫轉(zhuǎn)大寫的JS: document.getElementById("output").value = document.getElementById("i
nput").value.toUpperCase();
7.JS中的值類型:String,Number,Boolean,Null,Object,Function
8.JS中的字符型轉(zhuǎn)換成數(shù)值型:parseInt(),parseFloat()
9.JS中的數(shù)字轉(zhuǎn)換成字符型:(""+變量)
10.JS中的取字符串長(zhǎng)度是:(length)
11.JS中的字符與字符相連接使用+號(hào).
12.JS中的比較操作符有:==等于,!=不等于,>,>=,<.<=
13.JS中聲明變量使用:var來進(jìn)行聲明
14.JS中的判斷語句結(jié)構(gòu):if(condition){}else{}
15.JS中的循環(huán)結(jié)構(gòu):for([initial e xpression];[condition];[upadte e xpression]) {inside loop}
16.循環(huán)中止的命令是:break
17.JS中的函數(shù)定義:function functionName([parameter],...)
18.當(dāng)文件中出現(xiàn)多個(gè)form表單時(shí).可以用document.forms[0],document.forms[1]來代替.
19.窗口:打開窗口window.open(), 關(guān)閉一個(gè)窗口:window.close(), 窗口本身:self
20.狀態(tài)欄的設(shè)置:window.status="字符";
21.彈出提示信息:window.alert("字符");
22.彈出確認(rèn)框:window.confirm();
23.彈出輸入提示框:window.prompt();
24.指定當(dāng)前顯示鏈接的位置:window.location.href="URL"
25.取出窗體中的所有表單的數(shù)量:document.forms.length
26.關(guān)閉文檔的輸出流:document.close();
27.字符串追加連接符:+=
28.創(chuàng)建一個(gè)文檔元素:document.createElement(),document.createTextNode()
29.得到元素的方法:document.getElementById()
30.設(shè)置表單中所有文本型的成員的值為空:
var form = window.document.forms[0]
for (var i = 0; i if (form.elements.type == "text"){
form.elements.value = "";
}
}
31.復(fù)選按鈕在JS中判斷是否選中:document.forms[0].checkThis.checked (checked屬性代表為是否選中
返回TRUE或FALSE)
32.單選按鈕組(單選按鈕的名稱必須相同):取單選按鈕組的長(zhǎng)度document.forms[0].groupName.length
33.單選按鈕組判斷是否被選中也是用checked.
34.下拉列表框的值:document.forms[0].selectName.options[n].value (n有時(shí)用下拉列表框名稱加上.sel
ectedIndex來確定被選中的值)
35.字符串的定義:var myString = new String("This is lightsword");
36.字符串轉(zhuǎn)成大寫:string.toUpperCase(); 字符串轉(zhuǎn)成小寫:string.toLowerCase();
37.返回字符串2在字符串1中出現(xiàn)的位置:String1.indexOf("String2")!=-1則說明沒找到.
38.取字符串中指定位置的一個(gè)字符:StringA.charAt(9);
39.取出字符串中指定起點(diǎn)和終點(diǎn)的子字符串:stringA.substring(2,6);
40.數(shù)學(xué)函數(shù):Math.PI(返回圓周率),Math.SQRT2(返回開方),Math.max(value1,value2)返回兩個(gè)數(shù)中的最
在值,Math.pow(value1,10)返回value1的十次方,Math.round(value1)四舍五入函數(shù),Math.floor(Math.ra
ndom()*(n+1))返回隨機(jī)數(shù)
41.定義日期型變量:var today = new Date();
42.日期函數(shù)列表:dateObj.getTime()得到時(shí)間,dateObj.getYear()得到年份,dateObj.getFullYear()得到
四位的年份,dateObj.getMonth()得到月份,dateObj.getDate()得到日,dateObj.getDay()得到日期幾,dat
eObj.getHours()得到小時(shí),dateObj.getMinutes()得到分,dateObj.getSeconds()得到秒,dateObj.setTi
me(value)設(shè)置時(shí)間,dateObj.setYear(val)設(shè)置年,dateObj.setMonth(val)設(shè)置月,dateObj.setDate(va
l)設(shè)置日,dateObj.setDay(val)設(shè)置星期幾,dateObj.setHours設(shè)置小時(shí),dateObj.setMinutes(val)設(shè)置分,
dateObj.setSeconds(val)設(shè)置秒 [注意:此日期時(shí)間從0開始計(jì)]
43.FRAME的表示方式: [window.]frames[n].ObjFuncVarName,frames["frameName"].ObjFuncVarN
ame,frameName.ObjFuncVarName
44.parent代表父親對(duì)象,top代表最頂端對(duì)象
45.打開子窗口的父窗口為:opener
46.表示當(dāng)前所屬的位置:this
47.當(dāng)在超鏈接中調(diào)用JS函數(shù)時(shí)用:(javascript :)來開頭后面加函數(shù)名
48.在老的瀏覽器中不執(zhí)行此JS:
49.引用一個(gè)文件式的JS:
50.指定在不支持腳本的瀏覽器顯示的HTML:
51.當(dāng)超鏈和onCLICK事件都有時(shí),則老版本的瀏覽器轉(zhuǎn)向a.html,否則轉(zhuǎn)向b.html.例:dfsadf
52.JS的內(nèi)建對(duì)象有:Array,Boolean,Date,Error,EvalError,Function,Math,Number,Object,RangeError,
ReferenceError,RegExp,String,SyntaxError,TypeError,URIError
53.JS中的換行:\n
54.窗口全屏大小:
55.JS中的all代表其下層的全部元素
56.JS中的焦點(diǎn)順序:document.getElementByid("表單元素").tabIndex = 1
57.innerHTML的值是表單元素的值:如
"how are you"

,則innerHTML的值就是:how are you
58.innerTEXT的值和上面的一樣,只不過不會(huì)把這種標(biāo)記顯示出來.
59.contentEditable可設(shè)置元素是否可被修改,isContentEditable返回是否可修改的狀態(tài).
60.isDisabled判斷是否為禁止?fàn)顟B(tài).disabled設(shè)置禁止?fàn)顟B(tài)
61.length取得長(zhǎng)度,返回整型數(shù)值
62.addBehavior()是一種JS調(diào)用的外部函數(shù)文件其擴(kuò)展名為.htc
63.window.focus()使當(dāng)前的窗口在所有窗口之前.
64.blur()指失去焦點(diǎn).與FOCUS()相反.
65.select()指元素為選中狀態(tài).
66.防止用戶對(duì)文本框中輸入文本:onfocus="this.blur()"
67.取出該元素在頁面中出現(xiàn)的數(shù)量:document.all.tags("div(或其它HTML標(biāo)記符)").length
68.JS中分為兩種窗體輸出:模態(tài)和非模態(tài).window.showModaldialog(),window.showModeless()
69.狀態(tài)欄文字的設(shè)置:window.status='文字',默認(rèn)的狀態(tài)欄文字設(shè)置:window.defaultStatus = '文字.';
70.添加到收藏夾:external.AddFavorite("http://www.dannyg.com"t;,"jaskdlf");
71.JS中遇到腳本錯(cuò)誤時(shí)不做任何操作:window.onerror = doNothing; 指定錯(cuò)誤句柄的語法為:window.on
error = handleError;
72.JS中指定當(dāng)前打開窗口的父窗口:window.opener,支持opener.opener...的多重繼續(xù).
73.JS中的self指的是當(dāng)前的窗口
74.JS中狀態(tài)欄顯示內(nèi)容:window.status="內(nèi)容"
75.JS中的top指的是框架集中最頂層的框架
76.JS中關(guān)閉當(dāng)前的窗口:window.close();
77.JS中提出是否確認(rèn)的框:if(confirm("Are you sure?"))else{alert("Not Ok");}
78.JS中的窗口重定向:window.navigate("http://www.sina.com.cn"t;);
79.JS中的打印:window.print()
80.JS中的提示輸入框:window.prompt("message","defaultReply");
81.JS中的窗口滾動(dòng)條:window.scroll(x,y)
82.JS中的窗口滾動(dòng)到位置:window.scrollby
83.JS中設(shè)置時(shí)間間隔:setInterval("expr",msecDelay)或setInterval(funcRef,msecDelay)或setTimeou
t
84.JS中的模態(tài)顯示在IE4+行,在NN中不行:showModalDialog("URL"[,arguments][,features]);
85.JS中的退出之前使用的句柄:function verifyClose(){event.returnValue="we really like you and ho
pe you will stay longer.";}} window.onbeforeunload=verifyClose;
86.當(dāng)窗體第一次調(diào)用時(shí)使用的文件句柄:onload()
87.當(dāng)窗體關(guān)閉時(shí)調(diào)用的文件句柄:onunload()
88.window.location的屬性: protocol(http:),hostname(example.com),port(80),host(e
xample.com:80),pathname("/a/a.html"),hash("#giantGizmo",指跳轉(zhuǎn)到相應(yīng)的錨記),href(全部的信
息)
89.window.location.reload()刷新當(dāng)前頁面.
90.window.history.back()返回上一頁,window.history.forward()返回下一頁,window.history.go(返回
第幾頁,也可以使用訪問過的URL)
91.document.write()不換行的輸出,document.writeln()換行輸出
92.document.body.noWrap=true;防止鏈接文字折行.
93.變量名.charAt(第幾位),取該變量的第幾位的字符.
94."abc".charCodeAt(第幾個(gè)),返回第幾個(gè)字符的ASCii碼值.
95.字符串連接:string.concat(string2),或用+=進(jìn)行連接
96.變量.indexOf("字符",起始位置),返回第一個(gè)出現(xiàn)的位置(從0開始計(jì)算)
97.string.lastIndexOf(searchString[,startIndex])最后一次出現(xiàn)的位置.
98.string.match(regExpression),判斷字符是否匹配.
99.string.replace(regExpression,replaceString)替換現(xiàn)有字符串.
100.string.split(分隔符)返回一個(gè)數(shù)組存儲(chǔ)值.
101.string.substr(start[,length])取從第幾位到指定長(zhǎng)度的字符串.
102.string.toLowerCase()使字符串全部變?yōu)樾?
103.string.toUpperCase()使全部字符變?yōu)榇髮?
104.parseInt(string[,radix(代表進(jìn)制)])強(qiáng)制轉(zhuǎn)換成整型.
105.parseFloat(string[,radix])強(qiáng)制轉(zhuǎn)換成浮點(diǎn)型.
106.isNaN(變量):測(cè)試是否為數(shù)值型.
107.定義常量的關(guān)鍵字:const,定義變量的關(guān)鍵字:var
--------------------------------------------------------------------------------------------------------------------------------
javascript38種小技巧,推薦新手查看。
事件源對(duì)象
event.srcElement.tagName
event.srcElement.type
捕獲釋放
event.srcElement.setCapture();
event.srcElement.releaseCapture();
事件按鍵
event.keyCode
event.shiftKey
event.altKey
event.ctrlKey
事件返回值
event.returnValue
鼠標(biāo)位置
event.x
event.y
窗體活動(dòng)元素
document.activeElement
綁定事件
document.captureEvents(Event.KEYDOWN);
訪問窗體元素
document.all("txt").focus();
document.all("txt").select();
窗體命令
document.execCommand
窗體COOKIE
document.cookie
菜單事件
document.oncontextmenu
創(chuàng)建元素
document.createElement("SPAN");
根據(jù)鼠標(biāo)獲得元素:
document.elementFromPoint(event.x,event.y).tagName=="TD
document.elementFromPoint(event.x,event.y).appendChild(ms)
窗體圖片
document.images[索引]
窗體事件綁定
document.onmousedown=scrollwindow;
元素
document.窗體.elements[索引]
對(duì)象綁定事件
document.all.xxx.detachEvent('onclick',a);
插件數(shù)目
navigator.plugins
取變量類型
typeof($js_libpath) == "undefined"
下拉框
下拉框.options[索引]
下拉框.options.length
查找對(duì)象
document.getElement****yName("r1");
document.getElementById(id);
定時(shí)
timer=setInterval('scrollwindow()',delay);
clearInterval(timer);
UNCODE編碼
escape() ,unescape
父對(duì)象
obj.parentElement(dhtml)
obj.parentNode(dom)
交換表的行
TableID.moveRow(2,1) document.all.csss.href = "a.css";
替換CSS

并排顯示
display:inline
隱藏焦點(diǎn)
hidefocus=true
根據(jù)寬度換行
style="word-break:break-all"
自動(dòng)刷新
<meta HTTP-EQUIV="refresh" CONTENT="8;URL=http://c98.yeah.net">
簡(jiǎn)單郵件
<a href="mailto:aaa@bbb.com?subject=ccc&body=xxxyyy">
快速轉(zhuǎn)到位置
obj.scrollIntoView(true)

<a name="first">
<a href="#first">anchors</a>
網(wǎng)頁傳遞參數(shù)
location.search();
可編輯
obj.contenteditable=true
執(zhí)行菜單命令
obj.execCommand
雙字節(jié)字符
/[^\x00-\xff]/
漢字
/[\u4e00-\u9fa5]/
讓英文字符串超出表格寬度自動(dòng)換行
word-wrap: break-word; word-break: break-all;
透明背景
<IFRAME src="1.htm" width=300 height=180 allowtransparency></iframe>
獲得style內(nèi)容
obj.style.cssText
HTML標(biāo)簽
document.documentElement.innerHTML
第一個(gè)style標(biāo)簽
document.styleSheets[0]
style標(biāo)簽里的第一個(gè)樣式
document.styleSheets[0].rules[0]
防止點(diǎn)擊空鏈接時(shí),頁面往往重置到頁首端。
<a href="javascript:function()">word</a>
上一網(wǎng)頁源
asp:
request.servervariables("HTTP_REFERER")
javascript:
document.referrer
釋放內(nèi)存
CollectGarbage();
禁止右鍵
document.oncontextmenu = function() { return false;}
禁止保存
<noscript><iframe src="*.htm"></iframe></noscript>
禁 止選取<bodyonmouseup="document.selection.empty()>
禁止粘貼
<input type=text>
地址欄圖標(biāo)
<link rel="Shortcut Icon" href="favicon.ico">
favicon.ico 名字最好不變16*16的16色,放虛擬目錄根目錄下
收藏欄圖標(biāo)
<link rel="Bookmark" href="favicon.ico">
查看源碼
<input type=button value=查看網(wǎng)頁源代碼>
關(guān)閉輸入法
<input style="ime-mode:disabled">
自動(dòng)全選
<input type=text name=text1 value="123">
ENTER鍵可以讓光標(biāo)移到下一個(gè)輸入框
<input>
文本框的默認(rèn)值
<input type=text value="123">
title換行
obj.title = "123 sdfs "
獲得時(shí)間所代表的微秒
var n1 = new Date("2004-10-10".replace(/-/g, "\/")).getTime()
窗口是否關(guān)閉
win.closed
checkbox扁平
<input type=checkbox style="position: absolute; clip:rect(5px 15px 15px 5px)"><br>
獲取選中內(nèi)容
document.selection.createRange().duplicate().text
自動(dòng)完成功能
<input type=text autocomplete=on>打開該功能
<input type=text autocomplete=off>關(guān)閉該功能
窗口最大化
<body>
無關(guān)閉按鈕IE
window.open("aa.htm", "meizz", "fullscreen=7");
統(tǒng)一編碼/解碼
alert(decodeURIComponent(encodeURIComponent("http://你好.com?as= hehe")))
encodeURIComponent對(duì)":"、"/"、";" 和 "?"也編碼
表格行指示
<tr>

您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP