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

首頁 > 編程 > JavaScript > 正文

js 頁面元素的幾個用法總結

2019-11-20 21:40:29
字體:
來源:轉載
供稿:網友

對象屬性

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

―――――――――――――――――――――――
常用對象方法

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

body-主體子對象

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

常用對象事件

document.body.onclick=”func()” //鼠標指針單擊對象是觸發
document.body.onmouseover=”func()” //鼠標指針移到對象時觸發
document.body.onmouseout=”func()” //鼠標指針移出對象時觸發
―――――――――――――――――――――――
location-位置子對象

document.location.hash // #號后的部分
document.location.host // 域名+端口號//好像返回的是主機名localhost,沒有返回端口號
document.location.hostname // 域名
document.location.href // 完整URL
document.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

例如:

復制代碼 代碼如下:

<div>請選中這里的部分文字。</div>
<div><input type="button" value="請選中部分文字,然后點擊這里執行 empty" onclick="javascript:Foo();" /></div>
<script type="text/javascript" language="javascript">
function Foo()
{
    document.selection.empty();
}
</script>

selection的createRange方法

document.selection.createRange() 根據當前文字選擇返回 TextRange 對象,或根據控件選擇返回 ControlRange 對象。

配合 execCommand,在 HTML 編輯器中很有用,比如:文字加粗、斜體、復制、粘貼、創建超鏈接等。

這些好像都是只有在IE下才能實現。。

―――――――――――――――――――――――

images集合(頁面中的圖象)

a)通過集合引用
document.images //對應頁面上的img標簽
document.images.length //對應頁面上img標簽的個數
document.images[0] //第1個img標簽
document.images[i] //第i-1個img標簽

b)通過name屬性直接引用
img name=”oImage”
document.images.oImage //document.images.name屬性

c)引用圖片的src屬性
document.images.oImage.src //document.images.name屬性.src

d)創建一個圖象
var oImage
oImage = new Image()
document.images.oImage.src=”1.jpg”
同時在頁面上建立一個img /標簽與之對應就可以顯示

―――――――――――――――――――――――-

forms集合(頁面中的表單)

a)通過集合引用
document.forms //對應頁面上的form標簽
document.forms.length //對應頁面上/formform標簽的個數
document.forms[0] //第1個/formform標簽
document.forms[i] //第i-1個/formform標簽
document.forms[i].length //第i-1個/formform中的控件數
document.forms[i].elements[j] //第i-1個/formform中第j-1個控件

b)通過標簽name屬性直接引用
/formform name=”Myform”>input name=”myctrl”/>/form
document.Myform.myctrl //document.表單名.控件名

c)訪問表單的屬性
document.forms[i].name //對應form name>屬性
document.forms[i].action //對應/formform action>屬性
document.forms[i].encoding //對應/formform enctype>屬性
document.forms[i].target //對應/formform target>屬性

document.forms[i].appendChild(oTag) //動態插入一個控件
document.all.oDiv //引用圖層oDiv
document.all.oDiv.style.display=”" //圖層設置為可視
document.all.oDiv.style.display=”none” //圖層設置為隱藏
document.getElementId(”oDiv”) //通過getElementId引用對象
document.getElementId(”oDiv”).style=”"
document.getElementId(”oDiv”).display=”none”
/*document.all表示document中所有對象的集合
只有ie支持此屬性,因此也用來判斷瀏覽器的種類*/

圖層對象的4個屬性
document.getElementById(”ID”).innerText //動態輸出文本
document.getElementById(”ID”).innerHTML //動態輸出HTML
document.getElementById(”ID”).outerText //同innerText
document.getElementById(”ID”).outerHTML //同innerHTML

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 杨浦区| 天津市| 平顶山市| 普兰店市| 高尔夫| 陆良县| 宣城市| 沾化县| 辰溪县| 大石桥市| 尤溪县| 广安市| 安庆市| 临泽县| 忻城县| 东乡县| 温宿县| 喜德县| 黔南| 葫芦岛市| 昌邑市| 岳池县| 广州市| 泽州县| 沁水县| 永川市| 正宁县| 石阡县| 阳城县| 海原县| 瓮安县| 高邑县| 安仁县| 开鲁县| 怀化市| 蒙城县| 通海县| 陈巴尔虎旗| 昌平区| 佛冈县| 马边|