1祠斧、添加事件
添加事件方式速缆,見(jiàn)代碼
顯示隱藏圖片
操作div的display屬性规哪,在block和none之間切換即可
this使用
在匿名函數(shù)中的this就是當(dāng)前對(duì)象
在onclick=demo(this) 就是當(dāng)前節(jié)點(diǎn)
修改內(nèi)容
this.innerHTML = 'xxx'
切換背景色
表單內(nèi)容控制
見(jiàn)代碼
2烁落、onload函數(shù)
window的事件鸟蜡,windows.onload = function () {} 是在整個(gè)文檔加載完畢之后執(zhí)行膜赃,但是自己寫(xiě)的onclick的點(diǎn)擊函數(shù)不能寫(xiě)到onload里面,因?yàn)閮?nèi)部函數(shù)只能在內(nèi)部使用揉忘,不能再外部使用
如果實(shí)在是想用跳座,
window.lala = function () {}
3、選項(xiàng)卡
見(jiàn)代碼
4泣矛、定時(shí)器
定時(shí)器:分為兩種躺坟,一種是周期性定時(shí)器,一種是一次性定時(shí)器
周期性:每隔5s執(zhí)行一次函數(shù)
一次性:幾秒之后執(zhí)行一次函數(shù)乳蓄,執(zhí)行完畢定時(shí)器結(jié)束
var timer = setTimeout(fn, 5000)
5000ms之后執(zhí)行fn一次咪橙。然后結(jié)束
銷(xiāo)毀定時(shí)器 clearTimeout(timer)
計(jì)數(shù)器
圖片消失
5、獲取非行內(nèi)樣式
IE瀏覽器獲取非行內(nèi)樣式方式
obj.currentStyle['name']
火狐和谷歌獲取方式
getComputedStyle(odiv, null)['width']
獲取非行內(nèi)樣式的兼容性寫(xiě)法
function getStyle(obj, name) {
return obj.currentStyle ? obj.currentStyle[name] : getComputedStyle(obj, null)[name]
}
6虚倒、BOM操作
window.setTimeout,window.setInterval
window.alert\window.confirm
window.open
window.history(back美侦、go)
history.go(1) 去往前一個(gè)網(wǎng)址
history.go(2) 去往后一個(gè)網(wǎng)址
history.back() 倒退一個(gè)網(wǎng)址
location
href : 讀取得到當(dāng)前的url,設(shè)置跳轉(zhuǎn)到指定的url
reload() : 刷新整個(gè)頁(yè)面
7魂奥、DOM操作
children
parentNode
firstElementChild
lastElementChild
previousElementSibling
nextElementSibling
firstChild
lastChild
previousSibling
nextSibling
tagName
createElement
removeChild
appendChild
insertBefore
setAttribute getAttribute
8菠剩、select下拉框和oninput事件
onchange : 事件,用戶點(diǎn)擊下拉框觸發(fā)
selectedIndex : 用戶點(diǎn)擊的option的下標(biāo)耻煤,下標(biāo)從0開(kāi)始
options : osel.options 可以得到所有的option對(duì)象具壮,這是一個(gè)數(shù)組
input框的oninput事件,只要內(nèi)容改變哈蝇,就會(huì)觸發(fā)