JavaScript使用小技巧

1.收藏時用圖標顯示
<linkREL="SHORTCUTICON"href="http://www.asp888.net/site.ico">
2.TD內容實現不換行
只要使用noWrap屬性即可
3.獲得客戶端文件大小
<imgsrc="http://www.webucn.com/web/p_w_picpaths/banner.gif"onmouseover="this.alt='文件大小爲:'+this.fileSize+'字節'">
4.動態刪除元素
img1.removeNode(true)

5.模擬按鍵:

varWshShell=newActiveXObject("WScript.Shell");
WshShell.sendKeys("{F11}");

6.以下語句不需要糾錯判斷
for(i=2;i<1;i++){}
7.把js文件羣打包掉用
<scriptarchive=utils.jarsrc=\'#\'"/script>
8.獲得當前選中文本
document.getSelection()
9.獲得對象在document.all[]中元素的下標
txt1.sourceIndex
10.滾動文檔到窗口頂部或底部
txt1.scrollIntoView(true)
11.段落自動縮進
<pstyle=text-indent:26px>內容</p>
12.客戶端IP地址
Request.ServerVariables("REMOTE_HOST")
13.元素投影(可徹底解決網頁中投影問題)
filter:progid:DXImageTransform.Microsoft.Shadow(color='gray',Direction=135,Strength=3)
14.圖片熱區焦點隱藏
<imghideFocus>
15.不能在onload事件中open窗口,否則會被攔截
16.選擇本地文件時改變圖片源
<inputtype="file"onpropertychange="img.src=\'#\'"/font>
17.獲取文件路徑
varstr="http://localhost/Home/manage/FCKeditor/dialog/fck_p_w_picpath.html";str=str.replace(/[^\/]+$/,"");
18.js中的trim
String.prototype.trim=function()
{
returnthis.replace(/(^[\s]*)|([\s]*$)/g,"");
}
19.定義樣式表的子元素樣式
.clsbutton{color:red}
21.文本框tab
<textareaonkeydown="if(event.keyCode==9){clipboardData.setData('Text','');execCommand('paste');returnfalse}"rows=8cols=28>
</textarea>
22.最大化窗口
<OBJECTclassid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"onreadystatechange="if(this.readyState==4)this.Click();"VIEWASTEXT><PARAMname="Command"value="Maximize"></OBJECT>
23.圖片title換行符
&#13;
24.對body的click事件重定義
document.body.alert()}
25.10進制轉換爲16進制
alert((255).toString(16))
26.隱藏鏈接提示
<style>
a{evt:expression(window.status='')}
</style>
<ahref=http://ywicc.com>nostatusinformation</a>
注意:expression爲獲焦或失焦時執行,可爲寄主創建一參數,使其只執行一次,用於表格控制
27.同時執行兩事件
functiondocument.onclick,document.onkeydown(){
window.alert('HelloWorld!!!');
}
28.不顯示圖片工具欄
<metahttp-equiv="p_w_picpathtoolbar"content="no">
29.頁面最大化
<OBJECTclassid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"onreadystatechange="if(this.readyState==4)this.Click();"VIEWASTEXT><PARAMname="Command"value="Maximize"></OBJECT>
30.提交到新的可自義窗口
<formmethod="post"action="1.htm"target="test"onSubmit="window.open('','test','width=100,height=100')">
<inputtype="submit">
</form>
31.用css控制表格間隔色
tr{background:expression=\'#\'"?"red":"")}
32.取得字符的asc碼
"s".charCodeAt(0)
33.獲得行對象所在行數
o.rowIndex
34.去掉最後一個字符
s.slice(0,-1)
35.獲得系統背景色
style=background=\'#\'"/font>
36.表格導出爲excel文件
客戶端提供鏈接,在服務器端輸出xls文件,由客戶保存到客戶端即可
服務器端改變文件名的方法是
Response.ContentType="application/vnd.ms-excel"
Response.AddHeader("Content-Disposition","p_w_upload;filename=demo.exe")
37.在模式窗口中鏈接
<basetarget="_self">
38.求兩點夾角
Math.atan2(y1-y0,x1-x0)*180/Math.PI

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章