DOM 方法是能够(在 HTML 元素上)执行的动作
DOM 属性是能够设置或改变的 HTML 元素的值
查找元素
document.getElementById() document.getElementsByTagName() document.getElementsByClassName();
改变元素
document.getElementById().innerHTML= newhtml;修改HTML
document.getElementById().attribute= new value; 修改属性
document.getElementById().setAttribute(attr,val);修改属性
document.getElementById().style.property = new style;改样式
document.getElementById().value=new value;
添加删除元素
document.createElement(element);创建元素
document.removeChild(element);删除元素
document.appendChild(element);添加元素
document.replaceChild(element);替换元素
document.write(text);写入HTML流,覆盖文档
事件
document.getElementById(id).onclick = function(){code};
事件属性:alert(message);警告框
clearInterval()
取消定时器;clearTimeout()
取消定时;confirm(message)
确认框;setInterval()
定时器;setTimeout();scrollTo()
加载完执行;window.onload=function(){}
window.history.back()
后退;window.location.href=跳转页面
简单的轮播图
var tp = document.getElementsByClassName('n1');
var xi = 0;
var tt = setInterval(function () {
for (i = 0; i < tp.length; i++) {
tp[i].style.display = 'none';
}
tp[xi].style.display = 'block';
if (xi == 4) {
xi = 0;
} else {
xi++;
}
}, 1000);
var ban=document.getElementsByClassName('b1')
ban[0].onmouseout=function(){
clearInterval (tt);
}
ban[0].onmouseout=function(){
ks();
}