DIV CSS 佈局教程網

JS 刷新頁面的常用語句大集合
編輯:JavaScript基礎知識     

如何使用 jQuery 刷新當前頁面

下面介紹幾種頁面刷新方法,有時會用到:

window.location.reload() 刷新當前頁面。
parent.location.reload() 刷新父親對象(用於框架)。
opener.location.reload() 刷新父窗口對象(用於單開窗口)。
top.location.reload() 刷新最頂端對象(用於多開窗口)。

下面再整理一些常用的 JavaScript 基礎語句:

1. document.write("") 為輸出語句。
2. JS 中的注釋為 //。
3. 傳統的 HTML 文檔順序是:document -> html -> (head, body)。
4. 一個瀏覽器窗口中的 DOM 順序是:window -> (navigator, screen, history, location, document)。
5. 得到表單中元素的名稱和值:document.getelementbyid("表單元素的 id 號").name(或 value)。
6. 小寫轉大寫:document.getelementbyid("output").value = document.getelementbyid("input").value.touppercase();。
7. JS 中的值類型:string、number、boolean、null、object、function。
8. 字符型轉數值型:parseint()、parsefloat()。
9. 數字轉字符型:("" + 變量)。
10. 取字符串長度:(length)。
11. 字符串相連使用 + 號。
12. 比較操作符:== 等於、!= 不等於、>、>=、<、<=。
13. 聲明變量使用 var。
14. 判斷語句結構:if(condition){}else{}。
15. 循環結構:for([initial expression];[condition];[update expression]) {inside loop}。
16. 循環中止命令:break。
17. 函數定義:function functionname([parameter],…){statement[s]}。
18. 多個 form 表單時,可用 document.forms[0]、document.forms[1] 代替。
19. 窗口:打開 window.open(),關閉 window.close(),窗口本身 self。
20. 狀態欄設置:window.status = "字符";。
21. 彈出提示信息:window.alert("字符");。
22. 彈出確認框:window.confirm();。
23. 彈出輸入提示框:window.prompt();。
24. 指定當前顯示鏈接位置:window.location.href = "url"。
25. 取出窗體中所有表單的數量:document.forms.length。
26. 關閉文檔輸出流:document.close();。
27. 字符串追加連接符:+=。
28. 創建文檔元素:document.createelement()、document.createtextnode()。
29. 得到元素的方法:document.getelementbyid()。
30. 引用外部 JS 文件:<script type="text/javascript" src="aaa.js"></script>。
31. 指定不支持腳本的瀏覽器顯示的 HTML:<noscript></noscript>。
32. 超鏈和 onclick 事件都有時,老版本瀏覽器轉向 a.html,否則轉向 b.html,例如:<a href="a.html" onclick="location.href='b.html';return false">dfsadf</a>。
33. JS 內建對象有:array、boolean、date、error、evalerror、function、math、number、object、rangeerror、referenceerror、regexp、string、syntaxerror、typeerror、urierror。
34. JS 中的換行:/n。
35. 窗口全屏大小:<script>function fullscreen(){ this.moveto(0,0);this.outerwidth=screen.availwidth;this.outerheight=screen.availheight;}window.maximize=fullscreen;</script>。
36. JS 中的 all 代表其下層的全部元素。
37. 焦點順序:document.getelementbyid("表單元素").tabindex = 1。
38. innerhtml 的值是表單元素的值,如 how are you,則 innerhtml 的值就是 how are you。
39. innertext 的值和上面一樣,只不過不會把 em 這種標記顯示出來。
40. contenteditable 可設置元素是否可被修改,iscontenteditable 返回是否可修改的狀態。
41. isdisabled 判斷是否為禁止狀態,disabled 設置禁止狀態。
42. length 取得長度,返回整型數值。
43. addbehavior() 是一種 JS 調用的外部函數文件,擴展名為 .htc。
44. window.focus() 使當前窗口在所有窗口之前。
45. blur() 指失去焦點,與 focus() 相反。
46. select() 指元素為選中狀態。
47. 防止用戶對文本框輸入文本:onfocus="this.blur()"。
48. 取出該元素在頁面中出現的數量:document.all.tags("div(或其它 html 標記符)").length。
49. JS 中分兩種窗體輸出:模態和非模態,window.showmodaldialog()、window.showmodeless()。
50. 狀態欄文字設置:window.status='文字',默認狀態欄文字設置:window.defaultstatus = '文字'。
51. 添加到收藏夾:external.addfavorite("https://www.google.com","google");。
52. 遇到腳本錯誤時不做任何操作:window.onerror = donothing; 指定錯誤句柄:window.onerror = handleerror;。
53. 指定當前打開窗口的父窗口:window.opener,支持 opener.opener… 的多重繼續。
54. self 指當前窗口。
55. 狀態欄顯示內容:window.status="內容"。
56. top 指框架集中最頂層的框架。
57. 關閉當前窗口:window.close();。
58. 提出是否確認的框:if(confirm("are you sure?")){alert("ok");}else{alert("not ok");}。
59. 窗口重定向:window.navigate("https://www.google.com");。
60. 打印:window.print()。
61. 提示輸入框:window.prompt("message","defaultreply");。
62. 窗口滾動條:window.scroll(x,y)。
63. 窗口滾動到位置:window.scrollby。
64. 設置時間間隔:setinterval("expr",msecdelay) 或 setinterval(funcref,msecdelay) 或 settimeout。
65. 模態顯示在 IE4+ 行,NN 中不行:showmodaldialog("url"[,arguments][,features]);。
66. 退出之前使用的句柄:function verifyclose(){event.returnvalue="we really like you and hope you will stay longer.";} window.onbeforeunload=verifyclose;。
67. 窗體第一次調用時使用的文件句柄:onload()。
68. 窗體關閉時調用的文件句柄:onunload()。
69. window.location 的屬性:protocol(http:)、hostname(www.example.com)、port(80)、host(www.example.com:80)、pathname("/a/a.html")、hash("#giantgizmo",指跳轉到相應的錨記)、href(全部信息)。
70. window.location.reload() 刷新當前頁面;parent.location.reload() 刷新父親對象;opener.location.reload() 刷新父窗口對象;top.location.reload() 刷新最頂端對象。
71. window.history.back() 返回上一頁,window.history.forward() 返回下一頁,window.history.go(返回第幾頁,也可用訪問過的 url)。
72. document.write() 不換行輸出,document.writeln() 換行輸出。
73. document.body.nowrap=true; 防止鏈接文字折行。
74. 變量名.charat(第幾位),取該變量的第幾位字符。
75. "abc".charcodeat(第幾個),返回第幾個字符的 ascii 碼值。
76. 字符串連接:string.concat(string2),或用 += 連接。
77. 變量.indexof("字符",起始位置),返回第一個出現的位置(從 0 開始計算)。
78. string.lastindexof(searchstring[,startindex]) 最後一次出現的位置。
79. string.match(regexpression) 判斷字符是否匹配。
80. string.replace(regexpression,replacestring) 替換現有字符串。
81. string.split(分隔符) 返回一個數組存儲值。
82. string.substr(start[,length]) 取從第幾位到指定長度的字符串。
83. string.tolowercase() 使字符串全部變為小寫。
84. string.touppercase() 使全部字符變為大寫。
85. parseint(string[,radix(代表進制)]) 強制轉換成整型。
86. parsefloat(string[,radix]) 強制轉換成浮點型。
87. isnan(變量) 測試是否為數值型。
88. 定義常量的關鍵字:const,定義變量的關鍵字:var。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved