JS的Document屬性和方法小結(jié)
更新時間:2013年09月17日 18:00:42 作者:
Document想必大家并不陌生吧,在使用js的過程中會經(jīng)常遇到它,那么它有哪些屬性、哪些方法,在本文將以示例為大家詳細(xì)介紹下,希望對大家有所幫助
document.title //設(shè)置文檔標(biāo)題等價于HTML的title標(biāo)簽
document.bgColor //設(shè)置頁面背景色
document.fgColor //設(shè)置前景色(文本顏色)
document.linkColor //未點(diǎn)擊過的鏈接顏色
document.alinkColor //激活鏈接(焦點(diǎn)在此鏈接上)的顏色
document.vlinkColor //已點(diǎn)擊過的鏈接顏色
document.URL //設(shè)置URL屬性從而在同一窗口打開另一網(wǎng)頁
document.fileCreatedDate //文件建立日期,只讀屬性
document.fileModifiedDate //文件修改日期,只讀屬性
document.charset //設(shè)置字符集 簡體中文:gb2312
document.fileSize //文件大小,只讀屬性
document.cookie //設(shè)置和讀出cookie
———————————————————————
常用對象方法
document.write() //動態(tài)向頁面寫入內(nèi)容
document.createElement(Tag) //創(chuàng)建一個html標(biāo)簽對象
document.getElementById(ID) //獲得指定ID值的對象
document.getElementsByName(Name) //獲得指定Name值的對象
document.body.appendChild(oTag)
———————————————————————
body-主體子對象
document.body //指定文檔主體的開始和結(jié)束等價于body>/body>
document.body.bgColor //設(shè)置或獲取對象后面的背景顏色
document.body.link //未點(diǎn)擊過的鏈接顏色
document.body.alink //激活鏈接(焦點(diǎn)在此鏈接上)的顏色
document.body.vlink //已點(diǎn)擊過的鏈接顏色
document.body.text //文本色
document.body.innerText //設(shè)置body>…/body>之間的文本
document.body.innerHTML //設(shè)置body>…/body>之間的HTML代碼
document.body.topMargin //頁面上邊距
document.body.leftMargin //頁面左邊距
document.body.rightMargin //頁面右邊距
document.body.bottomMargin //頁面下邊距
document.body.background //背景圖片
document.body.appendChild(oTag) //動態(tài)生成一個HTML對象
常用對象事件
document.body.onclick=”func()” //鼠標(biāo)指針單擊對象是觸發(fā)
document.body.onmouseover=”func()” //鼠標(biāo)指針移到對象時觸發(fā)
document.body.onmouseout=”func()” //鼠標(biāo)指針移出對象時觸發(fā)
———————————————————————
location-位置子對象
document.location.hash // #號后的部分
document.location.host // 域名+端口號//好像返回的是主機(jī)名localhost,沒有返回端口號
document.location.hostname // 域名
document.location.href // 完整URL
document.location.pathname // 目錄部分
document.location.port // 端口號
document.location.protocol // 網(wǎng)絡(luò)協(xié)議(http:)
document.location.search // ?號后的部分
documeny.location.reload() //刷新網(wǎng)頁
document.location.reload(URL) //打開新的網(wǎng)頁
document.location.assign(URL) //打開新的網(wǎng)頁
document.location.replace(URL) //打開新的網(wǎng)頁
———————————————————————
selection-選區(qū)子對象
document.selection
例如:
<div>請選中這里的部分文字。</div>
<div><input type="button" value="請選中部分文字,然后點(diǎn)擊這里執(zhí)行 empty" onclick="javascript:Foo();" /></div>
<script type="text/javascript" language="javascript">
<!--
function Foo()
{
document.selection.empty();
}
-->
</script>
selection的createRange方法
document.selection.createRange() 根據(jù)當(dāng)前文字選擇返回 TextRange 對象,或根據(jù)控件選擇返回 ControlRange 對象。
配合 execCommand,在 HTML 編輯器中很有用,比如:文字加粗、斜體、復(fù)制、粘貼、創(chuàng)建超鏈接等。
這些好像都是只有在IE下才能實(shí)現(xiàn)。。
———————————————————————
images集合(頁面中的圖象)
a)通過集合引用
document.images //對應(yīng)頁面上的img標(biāo)簽
document.images.length //對應(yīng)頁面上img標(biāo)簽的個數(shù)
document.images[0] //第1個img標(biāo)簽
document.images[i] //第i-1個img標(biāo)簽
b)通過name屬性直接引用
img name=”oImage”
document.images.oImage //document.images.name屬性
c)引用圖片的src屬性
document.images.oImage.src //document.images.name屬性.src
d)創(chuàng)建一個圖象
var oImage
oImage = new Image()
document.images.oImage.src=”1.jpg”
同時在頁面上建立一個img /標(biāo)簽與之對應(yīng)就可以顯示
———————————————————————-
forms集合(頁面中的表單)
a)通過集合引用
document.forms //對應(yīng)頁面上的form標(biāo)簽
document.forms.length //對應(yīng)頁面上/formform標(biāo)簽的個數(shù)
document.forms[0] //第1個/formform標(biāo)簽
document.forms[i] //第i-1個/formform標(biāo)簽
document.forms[i].length //第i-1個/formform中的控件數(shù)
document.forms[i].elements[j] //第i-1個/formform中第j-1個控件
b)通過標(biāo)簽name屬性直接引用
/formform name=”Myform”>input name=”myctrl”/>/form
document.Myform.myctrl //document.表單名.控件名
c)訪問表單的屬性
document.forms[i].name //對應(yīng)form name>屬性
document.forms[i].action //對應(yīng)/formform action>屬性
document.forms[i].encoding //對應(yīng)/formform enctype>屬性
document.forms[i].target //對應(yīng)/formform target>屬性
document.forms[i].appendChild(oTag) //動態(tài)插入一個控件
document.all.oDiv //引用圖層oDiv
document.all.oDiv.style.display=”" //圖層設(shè)置為可視
document.all.oDiv.style.display=”none” //圖層設(shè)置為隱藏
document.getElementId(”oDiv”) //通過getElementId引用對象
document.getElementId(”oDiv”).style=”"
document.getElementId(”oDiv”).display=”none”
/*document.all表示document中所有對象的集合
只有ie支持此屬性,因此也用來判斷瀏覽器的種類*/
圖層對象的4個屬性
document.getElementById(”ID”).innerText //動態(tài)輸出文本
document.getElementById(”ID”).innerHTML //動態(tài)輸出HTML
document.getElementById(”ID”).outerText //同innerText
document.getElementById(”ID”).outerHTML //同innerHTML
------------------------------------------------------------------------------------------------------------------------------------------------------------------
document.readyState:判斷文檔是否加載完成。firefox不支持。
這個屬性是只讀的,傳回值有以下的可能:
0-UNINITIALIZED:XML 對象被產(chǎn)生,但沒有任何文件被加載。
1-LOADING:加載程序進(jìn)行中,但文件尚未開始解析。
2-LOADED:部分的文件已經(jīng)加載且進(jìn)行解析,但對象模型尚未生效。
3-INTERACTIVE:僅對已加載的部分文件有效,在此情況下,對象模型是有效但只讀的。
4-COMPLETED:文件已完全加載,代表加載成功。
document.onreadystatechange = subSomething;//當(dāng)頁面加載狀態(tài)改變的時候執(zhí)行這個方法.
function subSomething()
{
if(document.readyState == "complete"){ //當(dāng)頁面加載狀態(tài)為完全結(jié)束時進(jìn)入
//你要做的操作。
}
else if(document.readyState=="loading"){
}
}
比較好的例子:http://www.dbjr.com.cn/article/20445.htm
說明 :onreadystatechange 事件能辨識readyState 屬性的改變。
document.all(只被IE支持)
action:document.layers是Netscape 4.x專有的屬性,是一個代表所有由儲如<div><layer>等定位了的元素的數(shù)組通常也是用<div> 或<layer>對象的id屬性來引用的,但是這里面不包含除此以外的其它元素
document.layers和document.all的用法是一樣的,功能也是相同的。所在我就只介紹一種用法:
document.all的意思是文檔的所有元素,也就是說它包含了當(dāng)前網(wǎng)頁的所有元素。它是以數(shù)組的形式保存元素的屬性的,所以我們可以用 document.all["元素名"].屬性名="屬性值"來動態(tài)改變元素的屬性。用這條語句,可以做出許許多多動態(tài)網(wǎng)頁效果,如:動態(tài)變換圖片、動態(tài)改變文本的背景、動態(tài)改變網(wǎng)頁的背景、動態(tài)改變圖片的大小、動態(tài)改變文字的大小各顏色等等。你簡直可以動態(tài)控制所有網(wǎng)頁元素。
document.all[]這個數(shù)組可以訪問文檔中所有元素。
例1(這個可以讓你理解文檔中哪些是對象)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Document.All Example</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
</head>
<body>
<h1>Example Heading</h1>
<hr />
<p>This is a <em>paragraph</em>. It is only a <em>paragraph.</em></p>
<p>Yet another <em>paragraph.</em></p>
<p>This final <em>paragraph</em> has <em id="special">special emphasis.</em></p>
<hr />
<script type="text/javascript">
<!--
var i,origLength;
origLength = document.all.length;
document.write('document.all.length='+origLength+"<br />");
for (i = 0; i < origLength; i++)
{
document.write("document.all["+i+"]="+document.all[i].tagName+"<br />");
}
//-->
</script>
</body>
</html>
它的執(zhí)行結(jié)果是:
Example Heading
--------------------------------------------------------------------------------
This is a paragraph. It is only a paragraph.
Yet another paragraph.
This final paragraph has special emphasis.
--------------------------------------------------------------------------------
document.all.length=18
document.all[0]=!
document.all[1]=HTML
document.all[2]=HEAD
document.all[3]=TITLE
document.all[4]=META
document.all[5]=BODY
document.all[6]=H1
document.all[7]=HR
document.all[8]=P
document.all[9]=EM
document.all[10]=EM
document.all[11]=P
document.all[12]=EM
document.all[13]=P
document.all[14]=EM
document.all[15]=EM
document.all[16]=HR
document.all[17]=SCRIPT
(注意它只可以在IE上運(yùn)行)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>單擊DIV變色</title>
<style type="text/css">
<!--
#docid{
height:400px;
width:400px;
background-color:#999;}
-->
</style>
</head>
<body><div id="docid" name="docname" onClick="bgcolor()"></div>
</body>
</html>
<script language="javascript" type="text/javascript">
<!--
function bgcolor(){
document.all[7].style.backgroundColor="#000"
}
-->
</script>
上面的這個例子讓你了解怎么訪問文檔中的一個特定元素,比如文檔中有一個DIV
<div id="docid" name="docname"></div>,你可以通過這個DIV的ID,NAME 或INDEX屬性訪問這個DIV:
document.all["docid"]
document.all["docname"]
document.all.item("docid")
document.all.item("docname")
document.all[7]
document.all.tags("div")則返回文檔中所有DIV數(shù)組,本例中只有一個DIV,所以用 document.all.tags("div")[0]就可以訪問了。
3、使用document.all[]
例3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Document.All Example #2</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
</head>
<body>
<!-- Works in Internet Explorer and compatible -->
<h1 id="heading1" align="center" style="font-size: larger;">DHTML Fun!!!</h1>
<form name="testform" id="testform" action="#" method="get">
<br /><br />
<input type="button" value="Align Left"
onclick="document.all['heading1'].align='left';" />//改變<h1& gt;</h1>標(biāo)簽對中的align屬性的值,下面的代碼作用相同
<input type="button" value="Align Center"
onclick="document.all['heading1'].align='center';" />
<input type="button" value="Align Right"
onclick="document.all['heading1'].align='right';" />
<br /><br />
<input type="button" value="Bigger"
onclick="document.all['heading1'].style.fontSize='xx-large';" />
<input type="button" value="Smaller"
onclick="document.all['heading1'].style.fontSize='xx-small';" />
<br /><br />
<input type="button" value="Red"
onclick="document.all['heading1'].style.color='red';" />
<input type="button" value="Blue"
onclick="document.all['heading1'].style.color='blue';" />
<input type="button" value="Black"
onclick="document.all['heading1'].style.color='black';" />
<br /><br />
<input type="text" name="userText" id="userText" size="30" />
<input type="button" value="Change Text"
onclick="document.all['heading1'].innerText=document.testform.userText.value;" /& gt;//改變<h1></h1>標(biāo)簽對中的文本內(nèi)容
</form>
</body>
</html>
document.bgColor //設(shè)置頁面背景色
document.fgColor //設(shè)置前景色(文本顏色)
document.linkColor //未點(diǎn)擊過的鏈接顏色
document.alinkColor //激活鏈接(焦點(diǎn)在此鏈接上)的顏色
document.vlinkColor //已點(diǎn)擊過的鏈接顏色
document.URL //設(shè)置URL屬性從而在同一窗口打開另一網(wǎng)頁
document.fileCreatedDate //文件建立日期,只讀屬性
document.fileModifiedDate //文件修改日期,只讀屬性
document.charset //設(shè)置字符集 簡體中文:gb2312
document.fileSize //文件大小,只讀屬性
document.cookie //設(shè)置和讀出cookie
———————————————————————
常用對象方法
document.write() //動態(tài)向頁面寫入內(nèi)容
document.createElement(Tag) //創(chuàng)建一個html標(biāo)簽對象
document.getElementById(ID) //獲得指定ID值的對象
document.getElementsByName(Name) //獲得指定Name值的對象
document.body.appendChild(oTag)
———————————————————————
body-主體子對象
document.body //指定文檔主體的開始和結(jié)束等價于body>/body>
document.body.bgColor //設(shè)置或獲取對象后面的背景顏色
document.body.link //未點(diǎn)擊過的鏈接顏色
document.body.alink //激活鏈接(焦點(diǎn)在此鏈接上)的顏色
document.body.vlink //已點(diǎn)擊過的鏈接顏色
document.body.text //文本色
document.body.innerText //設(shè)置body>…/body>之間的文本
document.body.innerHTML //設(shè)置body>…/body>之間的HTML代碼
document.body.topMargin //頁面上邊距
document.body.leftMargin //頁面左邊距
document.body.rightMargin //頁面右邊距
document.body.bottomMargin //頁面下邊距
document.body.background //背景圖片
document.body.appendChild(oTag) //動態(tài)生成一個HTML對象
常用對象事件
document.body.onclick=”func()” //鼠標(biāo)指針單擊對象是觸發(fā)
document.body.onmouseover=”func()” //鼠標(biāo)指針移到對象時觸發(fā)
document.body.onmouseout=”func()” //鼠標(biāo)指針移出對象時觸發(fā)
———————————————————————
location-位置子對象
document.location.hash // #號后的部分
document.location.host // 域名+端口號//好像返回的是主機(jī)名localhost,沒有返回端口號
document.location.hostname // 域名
document.location.href // 完整URL
document.location.pathname // 目錄部分
document.location.port // 端口號
document.location.protocol // 網(wǎng)絡(luò)協(xié)議(http:)
document.location.search // ?號后的部分
documeny.location.reload() //刷新網(wǎng)頁
document.location.reload(URL) //打開新的網(wǎng)頁
document.location.assign(URL) //打開新的網(wǎng)頁
document.location.replace(URL) //打開新的網(wǎng)頁
———————————————————————
selection-選區(qū)子對象
document.selection
例如:
復(fù)制代碼 代碼如下:
<div>請選中這里的部分文字。</div>
<div><input type="button" value="請選中部分文字,然后點(diǎn)擊這里執(zhí)行 empty" onclick="javascript:Foo();" /></div>
<script type="text/javascript" language="javascript">
<!--
function Foo()
{
document.selection.empty();
}
-->
</script>
selection的createRange方法
document.selection.createRange() 根據(jù)當(dāng)前文字選擇返回 TextRange 對象,或根據(jù)控件選擇返回 ControlRange 對象。
配合 execCommand,在 HTML 編輯器中很有用,比如:文字加粗、斜體、復(fù)制、粘貼、創(chuàng)建超鏈接等。
這些好像都是只有在IE下才能實(shí)現(xiàn)。。
———————————————————————
images集合(頁面中的圖象)
a)通過集合引用
document.images //對應(yīng)頁面上的img標(biāo)簽
document.images.length //對應(yīng)頁面上img標(biāo)簽的個數(shù)
document.images[0] //第1個img標(biāo)簽
document.images[i] //第i-1個img標(biāo)簽
b)通過name屬性直接引用
img name=”oImage”
document.images.oImage //document.images.name屬性
c)引用圖片的src屬性
document.images.oImage.src //document.images.name屬性.src
d)創(chuàng)建一個圖象
var oImage
oImage = new Image()
document.images.oImage.src=”1.jpg”
同時在頁面上建立一個img /標(biāo)簽與之對應(yīng)就可以顯示
———————————————————————-
forms集合(頁面中的表單)
a)通過集合引用
document.forms //對應(yīng)頁面上的form標(biāo)簽
document.forms.length //對應(yīng)頁面上/formform標(biāo)簽的個數(shù)
document.forms[0] //第1個/formform標(biāo)簽
document.forms[i] //第i-1個/formform標(biāo)簽
document.forms[i].length //第i-1個/formform中的控件數(shù)
document.forms[i].elements[j] //第i-1個/formform中第j-1個控件
b)通過標(biāo)簽name屬性直接引用
/formform name=”Myform”>input name=”myctrl”/>/form
document.Myform.myctrl //document.表單名.控件名
c)訪問表單的屬性
document.forms[i].name //對應(yīng)form name>屬性
document.forms[i].action //對應(yīng)/formform action>屬性
document.forms[i].encoding //對應(yīng)/formform enctype>屬性
document.forms[i].target //對應(yīng)/formform target>屬性
document.forms[i].appendChild(oTag) //動態(tài)插入一個控件
document.all.oDiv //引用圖層oDiv
document.all.oDiv.style.display=”" //圖層設(shè)置為可視
document.all.oDiv.style.display=”none” //圖層設(shè)置為隱藏
document.getElementId(”oDiv”) //通過getElementId引用對象
document.getElementId(”oDiv”).style=”"
document.getElementId(”oDiv”).display=”none”
/*document.all表示document中所有對象的集合
只有ie支持此屬性,因此也用來判斷瀏覽器的種類*/
圖層對象的4個屬性
document.getElementById(”ID”).innerText //動態(tài)輸出文本
document.getElementById(”ID”).innerHTML //動態(tài)輸出HTML
document.getElementById(”ID”).outerText //同innerText
document.getElementById(”ID”).outerHTML //同innerHTML
------------------------------------------------------------------------------------------------------------------------------------------------------------------
document.readyState:判斷文檔是否加載完成。firefox不支持。
這個屬性是只讀的,傳回值有以下的可能:
0-UNINITIALIZED:XML 對象被產(chǎn)生,但沒有任何文件被加載。
1-LOADING:加載程序進(jìn)行中,但文件尚未開始解析。
2-LOADED:部分的文件已經(jīng)加載且進(jìn)行解析,但對象模型尚未生效。
3-INTERACTIVE:僅對已加載的部分文件有效,在此情況下,對象模型是有效但只讀的。
4-COMPLETED:文件已完全加載,代表加載成功。
復(fù)制代碼 代碼如下:
document.onreadystatechange = subSomething;//當(dāng)頁面加載狀態(tài)改變的時候執(zhí)行這個方法.
function subSomething()
{
if(document.readyState == "complete"){ //當(dāng)頁面加載狀態(tài)為完全結(jié)束時進(jìn)入
//你要做的操作。
}
else if(document.readyState=="loading"){
}
}
比較好的例子:http://www.dbjr.com.cn/article/20445.htm
說明 :onreadystatechange 事件能辨識readyState 屬性的改變。
document.all(只被IE支持)
action:document.layers是Netscape 4.x專有的屬性,是一個代表所有由儲如<div><layer>等定位了的元素的數(shù)組通常也是用<div> 或<layer>對象的id屬性來引用的,但是這里面不包含除此以外的其它元素
document.layers和document.all的用法是一樣的,功能也是相同的。所在我就只介紹一種用法:
document.all的意思是文檔的所有元素,也就是說它包含了當(dāng)前網(wǎng)頁的所有元素。它是以數(shù)組的形式保存元素的屬性的,所以我們可以用 document.all["元素名"].屬性名="屬性值"來動態(tài)改變元素的屬性。用這條語句,可以做出許許多多動態(tài)網(wǎng)頁效果,如:動態(tài)變換圖片、動態(tài)改變文本的背景、動態(tài)改變網(wǎng)頁的背景、動態(tài)改變圖片的大小、動態(tài)改變文字的大小各顏色等等。你簡直可以動態(tài)控制所有網(wǎng)頁元素。
document.all[]這個數(shù)組可以訪問文檔中所有元素。
例1(這個可以讓你理解文檔中哪些是對象)
復(fù)制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Document.All Example</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
</head>
<body>
<h1>Example Heading</h1>
<hr />
<p>This is a <em>paragraph</em>. It is only a <em>paragraph.</em></p>
<p>Yet another <em>paragraph.</em></p>
<p>This final <em>paragraph</em> has <em id="special">special emphasis.</em></p>
<hr />
<script type="text/javascript">
<!--
var i,origLength;
origLength = document.all.length;
document.write('document.all.length='+origLength+"<br />");
for (i = 0; i < origLength; i++)
{
document.write("document.all["+i+"]="+document.all[i].tagName+"<br />");
}
//-->
</script>
</body>
</html>
它的執(zhí)行結(jié)果是:
Example Heading
--------------------------------------------------------------------------------
This is a paragraph. It is only a paragraph.
Yet another paragraph.
This final paragraph has special emphasis.
--------------------------------------------------------------------------------
document.all.length=18
document.all[0]=!
document.all[1]=HTML
document.all[2]=HEAD
document.all[3]=TITLE
document.all[4]=META
document.all[5]=BODY
document.all[6]=H1
document.all[7]=HR
document.all[8]=P
document.all[9]=EM
document.all[10]=EM
document.all[11]=P
document.all[12]=EM
document.all[13]=P
document.all[14]=EM
document.all[15]=EM
document.all[16]=HR
document.all[17]=SCRIPT
(注意它只可以在IE上運(yùn)行)
復(fù)制代碼 代碼如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>單擊DIV變色</title>
<style type="text/css">
<!--
#docid{
height:400px;
width:400px;
background-color:#999;}
-->
</style>
</head>
<body><div id="docid" name="docname" onClick="bgcolor()"></div>
</body>
</html>
<script language="javascript" type="text/javascript">
<!--
function bgcolor(){
document.all[7].style.backgroundColor="#000"
}
-->
</script>
上面的這個例子讓你了解怎么訪問文檔中的一個特定元素,比如文檔中有一個DIV
<div id="docid" name="docname"></div>,你可以通過這個DIV的ID,NAME 或INDEX屬性訪問這個DIV:
document.all["docid"]
document.all["docname"]
document.all.item("docid")
document.all.item("docname")
document.all[7]
document.all.tags("div")則返回文檔中所有DIV數(shù)組,本例中只有一個DIV,所以用 document.all.tags("div")[0]就可以訪問了。
3、使用document.all[]
例3
復(fù)制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Document.All Example #2</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
</head>
<body>
<!-- Works in Internet Explorer and compatible -->
<h1 id="heading1" align="center" style="font-size: larger;">DHTML Fun!!!</h1>
<form name="testform" id="testform" action="#" method="get">
<br /><br />
<input type="button" value="Align Left"
onclick="document.all['heading1'].align='left';" />//改變<h1& gt;</h1>標(biāo)簽對中的align屬性的值,下面的代碼作用相同
<input type="button" value="Align Center"
onclick="document.all['heading1'].align='center';" />
<input type="button" value="Align Right"
onclick="document.all['heading1'].align='right';" />
<br /><br />
<input type="button" value="Bigger"
onclick="document.all['heading1'].style.fontSize='xx-large';" />
<input type="button" value="Smaller"
onclick="document.all['heading1'].style.fontSize='xx-small';" />
<br /><br />
<input type="button" value="Red"
onclick="document.all['heading1'].style.color='red';" />
<input type="button" value="Blue"
onclick="document.all['heading1'].style.color='blue';" />
<input type="button" value="Black"
onclick="document.all['heading1'].style.color='black';" />
<br /><br />
<input type="text" name="userText" id="userText" size="30" />
<input type="button" value="Change Text"
onclick="document.all['heading1'].innerText=document.testform.userText.value;" /& gt;//改變<h1></h1>標(biāo)簽對中的文本內(nèi)容
</form>
</body>
</html>
您可能感興趣的文章:
相關(guān)文章
JS函數(shù)實(shí)現(xiàn)動態(tài)添加CSS樣式表文件
有時會使用一些改變心情方面的想法,比如JS函數(shù)實(shí)現(xiàn)動態(tài)添加CSS樣式表文件,這樣就可以做到隨機(jī)加載心情文件,需要的朋友可以了解下2012-12-12Javascript 按位左移運(yùn)算符使用介紹(<<)
這篇文章主要介紹了Javascript 按位左移運(yùn)算符 (<<) 將表達(dá)式數(shù)字轉(zhuǎn)換成二進(jìn)制,之后向左移表達(dá)式的位的相關(guān)資料,需要的朋友可以參考下2014-02-02javascript實(shí)現(xiàn)計(jì)算器功能詳解流程
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)簡單計(jì)算器小功能,只學(xué)書上的理論是遠(yuǎn)遠(yuǎn)不夠的,只有在實(shí)戰(zhàn)中才能獲得能力的提升,大家可以在本篇實(shí)例中查缺補(bǔ)漏,提升水平2021-11-11javascript的數(shù)據(jù)類型、字面量、變量介紹
javascript的數(shù)據(jù)類型、字面量、變量介紹,學(xué)習(xí)js的朋友可以參考下2012-05-05JavaScript中的getMilliseconds()方法使用詳解
這篇文章主要介紹了JavaScript中的getMilliseconds()方法使用詳解,是JS入門學(xué)習(xí)中的基礎(chǔ)知識,需要的朋友可以參考下2015-06-06關(guān)于js中alert彈出窗口文本換行問題簡單詳細(xì)說明
js中alert彈出窗口文本換行是一個小問題,本人很是郁悶,于是搜集整理下,曬出來和大家分享2012-12-12