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

首頁 > 網站 > WEB開發 > 正文

$(document)與$(window)的區別

2024-04-27 15:04:07
字體:
來源:轉載
供稿:網友

http://blog.sina.com.cn/s/blog_74f1a3280102uyxp.html

$(document)與$(window)的區別

$(window)和$(document)獲取到的對象不同。

1、Window 對象表示一個瀏覽器窗口或一個框架。在客戶端 javaScript 中,Window 對象是全局對象,所有的表達式都在當前的環境中計算.

2、Document 對象是 Window 對象的一部分,每個載入瀏覽器的 HTML 文檔都會成為 Document 對象.

$(window).height()和$(document).height()

$(window).height()代表了當前可見區域的大小,而$(document).height()則代表了整個文檔的高度,可視具體情況使用.

注意當瀏覽器窗口大小改變時(如最大化或拉大窗口后) $(window).height() 隨之改變,但是$(document).height()是不變的。

$(document).scrollTop() 獲取垂直滾動的距離 即當前滾動的地方的窗口頂端到整個頁面頂端的距離 $(document).scrollLeft() 這是獲取水平滾動條的距離

只需要獲取到$(document).scrollTop()==0的時候 就是頂端了

只要$(document).scrollTop()>=$(document).height()-$(window).height() 就可以知道已經滾動到底端了

$(document).height() //是獲取整個頁面的高度$(window).height() //是獲取當前 也就是你瀏覽器所能看到的頁面的那部分的高度.這個大小在你縮放瀏覽器窗口大小時會改變,與document是不一樣的

動手實驗

<script> $(function(){ $(document).scroll(function(){ $("#lb").html('$(document).scrollTop() '+$(document).scrollTop() +'<br>'+ '$(document).height() '+$(document).height() +'<br>'+ '$(window).height() ' +$(window).height()); }) });</script><div style="background-color: orange;height:2000px"></div> <span id="lb" style="top:0px;left:0px;position:fixed;font-size:30px"></span><!--一個固定的span標記 滾動時方便查看-->

document與window

請移步 http://blog.csdn.net/linghu_java/article/details/7300028

具體方法

一、Window對象  ————————————————–——————-     對象屬性  window //窗戶自身  window.self //引用本窗戶window=window.self  window.name //為窗戶命名  window.defaultStatus //設定窗戶狀態欄信息  window.location //URL地址,配備布置這個屬性可以打開新的頁面  ————————————————–——————-  對象方法  window.alert(“text”) //提示信息會話框  window.confirm(“text”) //確認會話框  window.PRompt(“text”) //要求鍵盤輸入會話框  window.setIntervel(“action”,time) //每一隔指定的時間(毫秒)就執行一次操作  window.clearInterval() //清除時間配備布置作用就是終止輪回  window.setTimeout(action,time) //隔了指定的時間(毫秒)執行一次操作  window.open() //打開新的窗戶  window.close() //關閉窗戶  ————————————————–——————-  成員對象  window.event  window.document //見document對象詳解  window.history  window.screen  window.navigator  window.external  ————————————————–——————-  window.history對象  window.history.length //瀏覽過的頁面數  history.back() //撤退退卻  history.forward() //進步  history.go(i) //前進或頭退到歷史記錄的第i個頁面  //i>0進步,i<0撤退退卻  ————————————————–——————-  window.screen對象    window.screen.width //屏幕寬度  window.screen.height //屏幕高度  window.screen.colorDepth //屏幕色深  window.screen.availWidth //可用寬度  window.screen.availHeight //可用高度(除去任務欄的高度)  ————————————————–——————-  window.external對象  window.external.AddFavorite(“地址”,”標題” ) //把網站新增到保藏夾  ————————————————–——————-  window.navigator對象  window.navigator.appCodeName //瀏覽器代碼名  window.navigator.appName //瀏覽器步伐名  window.navigator.appMinorVersion //瀏覽器補釘版本  window.navigator.cpuClass //cpu類型 x86  window.navigator.platform //操作體系類型 win32  window.navigator.plugins  window.navigator.opsProfile  window.navigator.userProfile  window.navigator.systemLanguage //客戶體系語言 zh-cn簡體中文  window.navigator.userLanguage //用戶語言,同上  window.navigator.appVersion //瀏覽器版本(包括 體系版本)  window.navigator.userAgent  window.navigator.onLine //用戶否在線  window.navigator.cookieEnabled //瀏覽器是否撐持cookie  window.navigator.mimeTypes  ==================================================

二、document對象

對象屬性:document.title                //設置文檔標題等價于HTML的document.bgColor              //設置頁面背景色document.fgColor              //設置前景色(文本顏色)document.linkColor            //未點擊過的鏈接顏色document.alinkColor           //激活鏈接(焦點在此鏈接上)的顏色document.vlinkColor           //已點擊過的鏈接顏色document.URL                  //設置URL屬性從而在同一窗口打開另一網頁document.fileCreatedDate      //文件建立日期,只讀屬性document.fileModifiedDate     //文件修改日期,只讀屬性document.fileSize             //文件大小,只讀屬性document.cookie               //設置和讀出cookiedocument.charset              //設置字符集 簡體中文:gb2312—————————-

常用對象方法

document.write()                     //動態向頁面寫入內容document_createElement_x_x_x(Tag)          //創建一個html標簽對象document.getElementByIdx_x_x_x(ID)          //獲得指定ID值的對象document.getElementsByName(Name)     //獲得指定Name值的對象document.body.a(oTag)

body-主體子對象

document.body                  //指定文檔主體的開始和結束等價于document.body.bgColor          //設置或獲取對象后面的背景顏色document.body.link             //未點擊過的鏈接顏色document.body.alink            //激活鏈接(焦點在此鏈接上)的顏色document.body.vlink            //已點擊過的鏈接顏色document.body.text             //文本色document.body.innerText        //設置…之間的文本document.body.innerHTML        //設置…之間的HTML代碼document.body.topMargin        //頁面上邊距document.body.leftMargin       //頁面左邊距document.body.rightMargin      //頁面右邊距document.body.bottomMargin     //頁面下邊距document.body.background       //背景圖片document.body.a(oTag) //動態生成一個HTML對象

常用對象事件

document.body.onclick=”func()”             //鼠標指針單擊對象是觸發document.body.onmouSEOver=”func()”         //鼠標指針移到對象時觸發document.body.onmouseout=”func()”          //鼠標指針移出對象時觸發

location-位置子對象

document.location.hash         // #號后的部分document.location.host         // 域名+端口號document.location.hostname     // 域名document.location.href         // 完整URLdocument.location.pathname     // 目錄部分document.location.port         // 端口號document.location.protocol     // 網絡協議(http:)document.location.search       // ?號后的部分

常用對象事件

documeny.location.reload()         //刷新網頁document.location.reload(URL)      //打開新的網頁document.location.assign(URL)      //打開新的網頁document.location.replace(URL)     //打開新的網頁========================================================================selection-選區子對象document.selection========================================================================images集合(頁面中的圖象):—————————-a)通過集合引用document.images                //對應頁面上的Window及document對象的區別img標簽document.images.length         //對應頁面上Window及document對象的區別img標簽的個數document.images[0]             //第1個Window及document對象的區別img標簽           document.images[i]             //第i-1個imgWindow及document對象的區別標簽—————————-b)通過nane屬性直接引用Window及document對象的區別document.images.oImage         //document.images.name屬性—————————-c)引用圖片的src屬性document.images.oImage.src     //document.images.name屬性.src—————————-d)創建一個圖象var oImageoImage = new Image()document.images.oImage.src=http://www.knowsky.com/”1.jpg”同時在頁面上建立一個Window及document對象的區別img標簽與之對應就可以顯示

示例代碼(動態創建圖象):

Window及document對象的區別


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 青海省| 勃利县| 信阳市| 衡山县| 苏尼特左旗| 壤塘县| 北票市| 星子县| 台北县| 平定县| 信阳市| 淮北市| 喀什市| 扎兰屯市| 忻城县| 南华县| 化德县| 探索| 康马县| 梁平县| 通州市| 淮南市| 武汉市| 鄂托克旗| 永兴县| 万宁市| 沿河| 龙海市| 三亚市| 武穴市| 双峰县| 安化县| 安徽省| 临猗县| 安宁市| 进贤县| 铜川市| 哈巴河县| 永康市| 子长县| 珠海市|