html document.getElement(s)By..
来源:互联网 发布:java泛型的通配符 编辑:程序博客网 时间:2024/06/06 10:38
document.getElementById
1、getElementById
作用:一般页面里ID是唯一的,用于准备定位一个元素
语法: document.getElementById(id)
参数:id :必选项为字符串(String)
返回值:对象; 返回相同id对象中的第一个,按在页面中出现的次序,如果无符合条件的对象,则返回 null
example:
document.getElementById("id1").value;
2、getElementsByName
作用:按元素的名称查找,返回一个同名元素的数组
语法: document.getElementsByName(name)
参数:name :必选项为字符串(String)
返回值:数组对象; 如果无符合条件的对象,则返回空数组,按在页面中出现的次序
作用:一般页面里ID是唯一的,用于准备定位一个元素
语法: document.getElementById(id)
参数:id :必选项为字符串(String)
返回值:对象; 返回相同id对象中的第一个,按在页面中出现的次序,如果无符合条件的对象,则返回 null
example:
document.getElementById("id1").value;
2、getElementsByName
作用:按元素的名称查找,返回一个同名元素的数组
语法: document.getElementsByName(name)
参数:name :必选项为字符串(String)
返回值:数组对象; 如果无符合条件的对象,则返回空数组,按在页面中出现的次序
注意:返回数组值为value属性的值,
如果某标签无value属性,当你添加上value属性并赋值后,getElementsByName也能取到其值,
当未对value属性赋值时, getElementsByName返回数组值将是undefined ,
但仍能获得相同name标签的个数document.getElementsByName(name).length
当未设置name属性时document.getElementsByName仍能使用,它将根据你id取得value属性的值
example:
document.getElementsByName("name1")[0].value;
document.getElementsByName("name1")[1].value;
example:
document.getElementsByName("name1")[0].value;
document.getElementsByName("name1")[1].value;
<span id='CBylawIndexName' class='normalNode' value='all' >全部</span>"
<span id='CBylawIndexName' class='normalNode' value='ALL' >全部</span>"
span标签其实没有name和value属性
但document.getElementsByName("CBylawIndexName")仍将取得value的值
3、getElementsByTagName
作用:按HTML标签名查询,返回一个相同标签元素的数组
语法: object.getElementsByTagName(tagname) object可以是document或event.srcElement.parentElement等
参数:tagname:必选项为字符串(String),根据HTML标签检索。
返回值:数组对象; 如果无符合条件的对象,则返回空数组,按在页面中出现的次序
example:
document.getElementsByTagName("p")[0].childNodes[0].nodeValue;
document.getElementsByTagName("p")[1].childNodes[0].nodeValue
3、getElementsByTagName
作用:按HTML标签名查询,返回一个相同标签元素的数组
语法: object.getElementsByTagName(tagname) object可以是document或event.srcElement.parentElement等
参数:tagname:必选项为字符串(String),根据HTML标签检索。
返回值:数组对象; 如果无符合条件的对象,则返回空数组,按在页面中出现的次序
example:
document.getElementsByTagName("p")[0].childNodes[0].nodeValue;
document.getElementsByTagName("p")[1].childNodes[0].nodeValue
0 0
- html document.getElement(s)By..
- 四个document.getElement(s)By
- getElement
- 获取document对象除了getElement方法,居然还可以使用css选择器方法!!!
- html DOCUMENT
- BOM getElement
- HTML DOM Document 对象
- HTML DOM Document 对象
- HTML DOM Document Object
- HTML DOM Document 方法
- HTML DOM Document 对象
- HTML Document对象简介
- HTML DOM Document 对象
- HTML DOM Document 对象
- HTML DOM Document 对象
- html DOM------document
- HTML DOM Document 对象
- HTML DOM Document 对象
- Unity 添加天空盒的两种方法
- PCI总线(国嵌笔记)
- hibernate主键生成策略
- 匈牙利算法
- boost::asio译文
- html document.getElement(s)By..
- Android 组件间的解耦
- 蓝桥杯 - 兰顿蚂蚁 (模拟)
- DMA的外设地址简单说明
- Android 百度地图 SDK v3.0.0 (四) 引入离线地图功能
- 【问题】html列表项,内容随着鼠标移动而变化的页面,怎样实现?
- PCI驱动程序(国嵌笔记)
- JPA
- 视觉SLAM漫淡 - 半闲居士