accp6.0 《使用javascript增強交互效果》學習筆記ch3 DOM編程

 
目標:
1.使用getElementById()方法訪問Dom元素
2.使用getElementsByName()方法訪問Dom元素
3.使用getElementsByTagName()方法訪問Dom元素
4.使用display樣式屬性控制元素的隱藏和顯示
 
關鍵詞:visibility 可見性   visible 可見  block 塊
 
history對象
方法
back()   加載history對象列表中的前一個URL   
forward()  加載history對象列表中的下一個URL
go()   加載history對象列表中的某一個具體URL (go(1)前進一頁,go(-1)後退一頁,go(0)載入當前頁)
 
location對象
屬性
host 設置或返回主機名和當前URL的端口號
hostname 設置或返回當前URL的主機名
href 設置或返回完整的URL
方法
reload() 重新加載當前文檔
例:<a href="javascript:location:history.reload()">刷新</a>
replace() 用新的文檔替換當前文檔
例:
<script type="text/javascript"> 
var str="Visit Microsoft!"
 document.write(str.replace(/Microsoft/, "W3School")) 
</script>

輸出:

Visit W3School!
 
例:全部替換
<script type="text/javascript"> 
var str="Welcome to Microsoft! "
str=str + "We are proud to announce that Microsoft has " 
str=str + "one of the largest Web Developers sites in the world." 
document.write(str.replace(/Microsoft/g, "W3School")) 
</script>



輸出

Welcome to W3School! We are proud to announce that W3School
has one of the largest Web Developers sites in the world.

document對象

屬性
referrer 返回載入當前文檔的文檔的URL
當前文檔如果不是通過超鏈接訪問的,則document.referrer的值爲null
URL 返回當文檔的URL
方法
getElementById() 返回對擁有指定id的第一個對象的引用
getElementByName() 返回帶有指定名稱的對象的集合
getElementByTagName() 返回帶有指定標籤名的對象的集合
write() 向文檔寫文本、HTML表達式或javascript代碼
元素的顯示和隱藏
visibility屬性設置元素是否可見
visibility屬性的值
visible 表示元素是可見的
hidden 表示元素是不可見的
語法: object.style.visibility="值"
display屬性設置是否顯示元素
display屬性常見值
none 表示此元素不會被顯示
block 表示此元素將顯示爲塊級元素,此元素前後會帶有換行符
語法: object.style.display="值"

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章