DOM对象

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();
}

  

 

window:浏览器打开的窗口
事件属性:alert(message);警告框;
setInterval(function(){},1000)定时器;
clearInterval()取消定时器;
setTimeout(function(){},1000);
clearTimeout();取消定时;

  

 

var para = document.createElement("p");
var node = document.createTextNode("这是新文本。");
para.appendChild(node);
var parent = document.getElementById("div1");
var child = document.getElementById("p1");
parent.replaceChild(para, child);

  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted @ 2019-12-14 15:23  静静地开始  阅读(151)  评论(0)    收藏  举报