Home  >  Article  >  Web Front-end  >  javascript中HTMLDOM操作详解_javascript技巧

javascript中HTMLDOM操作详解_javascript技巧

PHP中文网
PHP中文网Original
2017-06-07 14:24:491529browse

 一、定义:htmlDOM是一种面向对象的树的模型,它包含html中的所有元素;通过html可以找到所有包含在dom中的元素。

二、作用:

1、查找html元素

1)通过id查找元素(document.getElementById();)



var x=document.getElementById("d");

2)通过标签名查找元素

 


var x=document.getElementById("m");

var y=x.getElementByTagName("p");

3)通过类名查找元素

三、改变HTML

1)改变html内容

2)改变html属性

3)改变html样式

四、HTMLDOM事件

1)对事件做出反应

2)HTML事件属性

3)使用htmlDOM来分配事件

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn