国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

js對象知識

2019-11-07 23:57:47
字體:
來源:轉載
供稿:網友
javaScript 提供多個內建對象,比如 String、Date、Array 等等。Javascript 只有一種數字類型。所有 JavaScript 數字均為 64 位JavaScript 中的所有數字都存儲為根為 10 的 64 位(8 比特),浮點數。整數(不使用小數點或指數計數法)最多為 15 位。小數的最大位數是 17,但是浮點運算并不總是 100% 準確:如果前綴為 0,則 JavaScript 會把數值常量解釋為八進制數,如果前綴為 0 和 "x",則解釋為十六進制數。數字屬性和方法屬性:MAX VALUEMIN VALUENEGATIVE INFINITIVEPOSITIVE INFINITIVENaNPRototypeconstructor方法:toExponential()toFixed()toPrecision()toString()valueOf()下面的代碼將當前日期與 2008 年 8 月 9 日做了比較:var myDate=new Date();myDate.setFullYear(2008,8,9);var today = new Date();if (myDate>today){alert("Today is before 9th August 2008");}else{alert("Today is after 9th August 2008");}Boolean 對象Boolean(邏輯)對象用于將非邏輯值轉換為邏輯值(true 或者 false)。var myBoolean=new Boolean()Math 對象JavaScript 提供 8 種可被 Math 對象訪問的算數值:常數圓周率2 的平方根1/2 的平方根2 的自然對數10 的自然對數以 2 為底的 e 的對數以 10 為底的 e 的對數這是在 Javascript 中使用這些值的方法:(與上面的算數值一一對應)Math.EMath.PIMath.SQRT2Math.SQRT1_2Math.LN2Math.LN10Math.LOG2EMath.LOG10ERegExpRegExp 是正則表達式的縮寫對象用于規定在文本中檢索的內容。RegExp 對象有 3 個方法:test()、exec() 以及 compile()。瀏覽器對象模型 (BOM)所有 JavaScript 全局對象、函數以及變量均自動成為 window 對象的成員。全局變量是 window 對象的屬性。全局函數是 window 對象的方法。甚至 HTML DOM 的 document 也是 window 對象的屬性之一:有三種方法能夠確定瀏覽器窗口的尺寸(瀏覽器的視口,不包括工具欄和滾動條)。對于Internet Explorer、ChromeFirefoxOpera 以及 Safari:window.innerHeight - 瀏覽器窗口的內部高度window.innerWidth - 瀏覽器窗口的內部寬度對于 Internet Explorer 8、7、6、5:document.documentElement.clientHeightdocument.documentElement.clientWidth或者document.body.clientHeightdocument.body.clientWidth其他 Window 方法一些其他方法:window.open() - 打開新窗口window.close() - 關閉當前窗口window.moveTo() - 移動當前窗口window.resizeTo() - 調整當前窗口的尺寸Window Screenscreen.availWidth - 可用的屏幕寬度screen.availHeight - 可用的屏幕高度Window Locationwindow.location 對象在編寫時可不使用 window 這個前綴。location.hostname 返回 web 主機的域名location.pathname 返回當前頁面的路徑和文件名location.port 返回 web 主機的端口 (80 或 443)location.protocol 返回所使用的 web 協議(http:// 或 https://)location.href 屬性返回當前頁面的 URL。Window History為了保護用戶隱私,對 JavaScript 訪問該對象的方法做出了限制。history.back() - 與在瀏覽器點擊后退按鈕相同history.forward() - 與在瀏覽器中點擊按鈕向前相同Window Navigatorwindow.navigator 對象包含有關訪問者瀏覽器的信息。例:<div id="example"></div><script>txt = "<p>Browser CodeName: " + navigator.appCodeName + "</p>";txt+= "<p>Browser Name: " + navigator.appName + "</p>";txt+= "<p>Browser Version: " + navigator.appVersion + "</p>";txt+= "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>";txt+= "<p>Platform: " + navigator.platform + "</p>";txt+= "<p>User-agent header: " + navigator.userAgent + "</p>";txt+= "<p>User-agent language: " + navigator.systemLanguage + "</p>";document.getElementById("example").innerHTML=txt;</script>由于不同的瀏覽器支持不同的對象,您可以使用對象來檢測瀏覽器。例如,由于只有 Opera 支持屬性 "window.opera",您可以據此識別出 Opera。PopupAlert消息框JavaScript 中創建三種消息框:警告框alert("文本")、確認框confirm("文本")、提示框prompt("文本","默認值")提示框:function disp_prompt(){var name=prompt("請輸入您的名字","Bill Gates")if (name!=null && name!=""){document.write("你好!" + name + " 今天過得怎么樣?")}}確認框:function show_confirm(){var r=confirm("Press a button!");if (r==true){alert("You pressed OK!");}else{alert("You pressed Cancel!");}}警告框:function disp_alert(){alert("再次向您問好!在這里,我們向您演示" + '/n' + "如何向警告框添加折行。")}計時TimmingsetTimeout()未來的某時執行代碼clearTimeout()取消setTimeout()cookie 用來識別用戶。名字 cookie 密碼 cookie 日期 cookie首先,我們會創建一個可在 cookie 變量中存儲訪問者姓名的函數:function setCookie(c_name,value,expiredays){var exdate=new Date()exdate.setDate(exdate.getDate()+expiredays)document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())}上面這個函數中的參數存有 cookie 的名稱、值以及過期天數。在上面的函數中,我們首先將天數轉換為有效的日期,然后,我們將 cookie 名稱、值及其過期日期存入 document.cookie 對象。之后,我們要創建另一個函數來檢查是否已設置 cookie:function getCookie(c_name){if (document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "=") if (c_start!=-1) { c_start=c_start + c_name.length+1 c_end=document.cookie.indexOf(";",c_start) if (c_end==-1) c_end=document.cookie.length return unescape(document.cookie.substring(c_start,c_end)) } }return ""}上面的函數首先會檢查 document.cookie 對象中是否存有 cookie。假如 document.cookie 對象存有某些 cookie,那么會繼續檢查我們指定的 cookie 是否已儲存。如果找到了我們要的 cookie,就返回值,否則返回空字符串。最后,我們要創建一個函數,這個函數的作用是:如果 cookie 已設置,則顯示歡迎詞,否則顯示提示框來要求用戶輸入名字。function checkCookie(){username=getCookie('username')if (username!=null && username!="") {alert('Welcome again '+username+'!')}else { username=prompt('Please enter your name:',"") if (username!=null && username!="") { setCookie('username',username,365) } }}例子代碼:<html><head><script type="text/javascript">function getCookie(c_name){if (document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "=") if (c_start!=-1) { c_start=c_start + c_name.length+1 c_end=document.cookie.indexOf(";",c_start) if (c_end==-1) c_end=document.cookie.length return unescape(document.cookie.substring(c_start,c_end)) } }return ""}function setCookie(c_name,value,expiredays){var exdate=new Date()exdate.setDate(exdate.getDate()+expiredays)document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())}function checkCookie(){username=getCookie('username')if (username!=null && username!="") {alert('Welcome again '+username+'!')}else { username=prompt('Please enter your name:',"") if (username!=null && username!="") { setCookie('username',username,365) } }}</script></head><body onLoad="checkCookie()"></body></html> JavaScript 框架jQueryPrototypeMooTools
上一篇:Sqlite使用

下一篇:安卓推薦第三方庫

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 曲阳县| 周至县| 平舆县| 霍山县| 宜州市| 宜昌市| 鄂尔多斯市| 漯河市| 壶关县| 高青县| 大冶市| 钦州市| 拉孜县| 旬阳县| 封丘县| 安福县| 丹江口市| 亳州市| 蓬安县| 新安县| 海晏县| 铜梁县| 石林| 兰州市| 巨鹿县| 景谷| 准格尔旗| 中牟县| 德格县| 潍坊市| 武隆县| 驻马店市| 荆门市| 哈尔滨市| 茂名市| 吴江市| 儋州市| 天峨县| 类乌齐县| 江陵县| 庆元县|