getElementById,getElementsByName,getElementsByTagName的区别
1、getElementById 作用:一般页面里ID是唯一的,用于准备定为一个元素
语法: document.getElementById(id)
参数:id :必选项为字符串(String)
返回值:对象; 返回相同id对象中的第一个,按在页面中出现的次序,如果无符合条件的对象,则返回 null example:
document.getElementById("id1").value; 2、getElementsByName 作用:按元素的名称查找,返回一个同名元素的数组
语法: document.getElementsByName(name)
参数:name :必选项为字符串(String)
返回值:数组对象; 如果无符合条件的对象,则返回空数组,按在页面中出现的次序 example:
document.getElementsByName("name1")[0].value; //获取想要的相同的name的元素
document.getElementsByName("name1")[1].value;
3、getElementsByTagName 作用:按HTML标签名查询,返回一个相同标签元素的数组
语法: object.getElementsByTagName(tagname) object可以是document或event.srcElement.parentElement等
参数:tagname:必选项为字符串(String),根据HTML标签检索。
返回值:数组对象; 如果无符合条件的对象,则返回空数组,按在页面中出现的次序 总结:
1.getElementById返回值是id对象中的第一个
2.getElementsByName和getElementsByTagName返回的是数组对象
getElementById,getElementsByName,getElementsByTagName的区别的更多相关文章
- JS中getElementByID,getElementsByName,getElementsByTagName的区别
<input type="text" name="mynumber" id="mynum1" value="" / ...
- 区别getElementByID,getElementsByName,getElementsByTagName
以人来举例说明,人有能标识身份的身份证,有姓名,有类别(大人.小孩.老人)等. 1. ID 是一个人的身份证号码,是唯一的.所以通过getElementById获取的是指定的一个人. 2. Name ...
- getElementByID,getElementsByName,getElementsByTagName
<input type="checkbox" name="hobby" id="hobby1"> 音乐 <input ty ...
- document.getElementById(), getElementsByname(),getElementsByClassName(),getElementsByTagName()方法表示什么以及其意义
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- (6个name="hobby"的复选项,两个按钮)来区分三种方法的不同---区别getElementByID,getElementsByName,getElem
<form> 请选择你爱好:<br> <input type="checkbox" name="hobb ...
- 玩转DOM遍历——用NodeIterator实现getElementById,getElementsByTagName方法
先声明一下DOM2中NodeIterator和TreeWalker这两类型真的只是用来玩玩的,因为性能不行遍历起来超级慢,在JS中基本用不到它们,除了<高程>上有两三页对它的讲解外,谷歌的 ...
- getElementById getElementsByName 赋值
<script type="text/javascript"> window.onload=function ...
- js82:CSS的Style,image的重定位,getElementById,getElementsByTagName,location.href
原文发布时间为:2008-11-10 -- 来源于本人的百度文章 [由搬家工具导入] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tran ...
- Id.value与document.getElementById("Id").value的区别
如果标签Id在Form表单里面的话,直接Id.value就不能用了,而是要用Form.Id.value来取值或设置值 所以最好用document.getElementById("Id&quo ...
随机推荐
- callback 转换到 promise
最近项目迭代,从express到koa,面对callback,想偷懒,就想到了Proxy对象 new Proxy(docker,{ get : function (obj,name) { return ...
- 【JavaScript】放大镜效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- wordpress 首页调用文章 不同样式的方法
<?php $count = 1; $display_categories = array(1); foreach ($display_categories as $category) { ?& ...
- 替换url中某个参数的值或是添加某个参数的方法(js 分页上下页可以使用)
function changeUrl(base, find, value) { var offset = base.indexOf(find); var index; var rr = ''; if( ...
- A problem about rcssserver3d
When I enter rcssserver3d to the terminal, the system told me this problem: (SimulationServer) SimCo ...
- svn回滚版本
1.本地修改了内容,但是没有commit可以通过Revert-来覆盖当前版本. 2.已经commit了.首先第一步,应该知道需要回滚的版本编号, 第二步,选择 updata to revision
- C++的STL
今天,看一段代码的时候发现只一句话就做了个排序,是这样的: sort(rotateArray.begin(),rotateArray.end()); 很震惊,后来查了一下sort的用法, sort函数 ...
- 一步一步搭框架(asp.netmvc+easyui+sqlserver)-03
一步一步搭框架(asp.netmvc+easyui+sqlserver)-03 我们期望简洁的后台代码,如下: using System; using System.Collections.Gener ...
- IntelliJ IDEA手工安python装插件方法
IntelliJ IDEA手工安装插件方法 以IntelliJ IDEA 11.0.1安装python为例: (1)下载python插件地址:http://plugins.intellij.net/p ...
- const和readonly区别
内容来源<<你必须知道的.NET>>(转载) 标题:什么才是不变:const和readonly 内容: const:用 const 修饰符声明的成员叫常量,是在编译期初始化并嵌 ...