document.getElementById

1、getElementById

作用:一般页面里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;

<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

document.getElementById/Name/TagName的更多相关文章

  1. document.getElementById和document.querySelector的区别

    zepto中的$(".111")出错,jQuery中$(".111")不出错的原因: zepto用document.querySelector实现,jQuery ...

  2. 解决document.getElementById("")在IE7中误读成name的bug

    <!DOCTYPE html>      <html lang="en">      <head>          <meta char ...

  3. Id.value与document.getElementById("Id").value的区别

    如果标签Id在Form表单里面的话,直接Id.value就不能用了,而是要用Form.Id.value来取值或设置值 所以最好用document.getElementById("Id&quo ...

  4. document.getElementById()与 $()区别

    document.getElementById()返回的是DOM对象,而$()返回的是jQuery对象 什么是jQuery对象? ---就是通过jQuery包装DOM对象后产生的对象.jQuery对象 ...

  5. jQuery中,$('#main') 与 document.getElementById('main')是什么样的关系-转

    $('#main')[0]和document.getElementById('main')两个一模一样.解释:$('#main'):是一个jquery写法,#main是一个过滤器表示方法,表示查找一个 ...

  6. jquery中的$("#id")与document.getElementById("id")的区别

    以前一直认为jquery中的$("#id")和document.getElementByIdx_x("id")得到的效果是一样的,今天做特效的时候才发现并不是这 ...

  7. 【Asp.Net】document.getElementById 的属性介绍

    document.getElementById("id").style.xxx可以设置指定ID的控件的属性值. 主要支持以下一些属性设置: 盒子标签和属性对照 CSS语法(不区分大 ...

  8. 不绑架输入--document.getElementById("linkage_"+id_type+"_echo").value="";--联动

    <script> function w_linkage(id_type) { var selected = $("#linkage_"+id_type+"_t ...

  9. 获得输入框的文本document.getElementById('id').value;

    <input id="demo" type="text" value="" > x=document.getElementByI ...

随机推荐

  1. LINUX系统中高级网络服务:Bond、Team和网桥

    Bond 一.什么是Bond bond就是将两块网卡虚拟链接成一块网卡的技术.通过bond技术让多块网卡看起来是一个单独的以太网接口设备并具有相同的ip地址. 二.为什么要配置Bond 通过网卡绑定技 ...

  2. (转) MapReduce Design Patterns(chapter 2 (part 1))(二)

     CHAPTER 2 .Summarization Patterns 随着每天都有更多的数据加载进系统,数据量变得很庞大.这一章专注于对你的数据顶层的,概括性意见的设计模式,从而使你能扩展思路,但可能 ...

  3. Photon——Feature Overview 功能概述

    Photon——Feature Overview 功能概述   Feature Overview 功能概述        Photon is a real-time socket server and ...

  4. allow-hotplug eth0 allow-hotplug error

    /********************************************************************* * allow-hotplug eth0 error * ...

  5. js之敏感词过滤

    HTML <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <titl ...

  6. SQL夯实基础(九)MySQL联接查询算法

    书接上文<SQL夯实基础(八):联接运算符算法归类>. 这里先解释下EXPLAIN 结果中,第一行出现的表就是驱动表(Important!). 对驱动表可以直接排序,对非驱动表(的字段排序 ...

  7. selenium 上传文件方法补充——SendKeys、win32gui

    之前和大家说了input标签的上传文件的方式: <selenium2 python 自动化测试实战>(13)——上传文件 现在好多网站上传的标签并不是input,而是div之类的比如: 全 ...

  8. lapis 数据库配置

    备注:  目前支持 postgresql .mysql (实际使用大家可以尝试用下tidb.CockroachDB)   1. pg数据库配置 // config.lua local config = ...

  9. Go语言学习笔记 package

    加 Golang学习 QQ群共同学习进步成家立业工作 ^-^ 群号:96933959 strings import "strings" strings包实现了用于操作字符的简单函数 ...

  10. dos命令行连接操作ORACLE数据库

    C:\Adminstrator> sqlplus "/as sysdba" 查看是否连接到数据库 SQL> select status from v$instance; ...