document.getElementById & document.querySelector
document.getElementById & document.querySelector
https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll
https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector
https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById
getElementById 仅支持 id 选择器, 返回 An Element object
querySelector 支持各种选择器, 返回匹配的第一个 An HTMLElement object
https://developer.mozilla.org/en-US/docs/Web/API/Element
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement

- HTMLElement 是父类,base 接口
- Element 是子类,实现/继承于 HTMLElement 接口
demo

document.getElementById("demo");
<section id="demo">
</section>
document.querySelector("#demo")
<section id="demo">
</section>
document.querySelectorAll("#demo")
NodeList [section#demo]0: section#demolength: 1__proto__: NodeList
document.getElementById("demo") === document.querySelector("#demo")
true
document.getElementById("demo") == document.querySelector("#demo")
true
typeof document.getElementById("demo")
"object"
typeof document.querySelector("#demo")
"object"
document.getElementById & document.querySelector的更多相关文章
- 尝试document.getElementById()失败
document.getElementById() document.getElementsByTagName() 电脑重启,新建文件后尝试成功
- document.getElementsByName和document.getElementById用法
本文的问题在国外的一个网站得到了答案http://stackoverflow.com/questions/11235409/no-getelementbyid-for-body document.bo ...
- document.getElementById和document.querySelector的区别
zepto中的$(".111")出错,jQuery中$(".111")不出错的原因: zepto用document.querySelector实现,jQuery ...
- Id.value与document.getElementById("Id").value的区别
如果标签Id在Form表单里面的话,直接Id.value就不能用了,而是要用Form.Id.value来取值或设置值 所以最好用document.getElementById("Id&quo ...
- document.getElementById()与 $()区别
document.getElementById()返回的是DOM对象,而$()返回的是jQuery对象 什么是jQuery对象? ---就是通过jQuery包装DOM对象后产生的对象.jQuery对象 ...
- jQuery中,$('#main') 与 document.getElementById('main')是什么样的关系-转
$('#main')[0]和document.getElementById('main')两个一模一样.解释:$('#main'):是一个jquery写法,#main是一个过滤器表示方法,表示查找一个 ...
- jquery中的$("#id")与document.getElementById("id")的区别
以前一直认为jquery中的$("#id")和document.getElementByIdx_x("id")得到的效果是一样的,今天做特效的时候才发现并不是这 ...
- 【Asp.Net】document.getElementById 的属性介绍
document.getElementById("id").style.xxx可以设置指定ID的控件的属性值. 主要支持以下一些属性设置: 盒子标签和属性对照 CSS语法(不区分大 ...
- 不绑架输入--document.getElementById("linkage_"+id_type+"_echo").value="";--联动
<script> function w_linkage(id_type) { var selected = $("#linkage_"+id_type+"_t ...
随机推荐
- 设计模式c++(1)
本来是想把之前的<head first设计模式>看了,不过因为这本书是java实现的,跟c++还是略有区别. 于是找了一下,发现了一个不错的blog,打算连书带blog一起参考着看了. b ...
- java 读取text内容
public static String readToString(String fileName) { String encoding = "UTF-8"; File file ...
- cisco 4500X 交换机限速
一.配置步骤 1.定义ACL以匹配数据流 ip access-list extended aclname 2.配置流量分类和策略 class-map [match-all(默认:完全符合)/Match ...
- 通过f5的默认路由使服务器上网
1.通过f5的默认路由使服务器上网 1)将服务器的默认网关指到f5的floating ip 2)f5上配置
- nginx教程<二>(高可用)
1.nginx集群 对于访问量较大的网站来说,随着流量的增加单台服务器已经无法处理所有的请求,这时候需要多台服务器对大量的请求进行分流处理,即负载均衡. 而如果实现负载均衡,必须在网站的入口部署服务器 ...
- CyclicBarrier---可重用的循环栅栏
很多文章只是提了下可重用,具体这个栅栏怎么可重用的,很多没有说明,这里会解开你的疑惑. CyclicBarrier是一个同步工具类,它允许一组线程互相等待,直到达到某个公共屏障点.与CountDown ...
- HDU6311 Cover【欧拉路径 | 回路】
HDU6311 Cover 题意: 给出\(N\)个点的简单无向图,不一定联通,现在要用最少的路径去覆盖所有边,并且每条边只被覆盖一次,问最少路径覆盖数和各条路径 \(N\le 10^5\) 题解: ...
- 2015 Multi-University Training Contest 10(9/11)
2015 Multi-University Training Contest 10 5406 CRB and Apple 1.排序之后费用流 spfa用stack才能过 //#pragma GCC o ...
- Codeforces Round #655 (Div. 2) B. Omkar and Last Class of Math
题目链接:https://codeforces.com/contest/1372/problem/B 题意 给出一个正整数 $n$,找到两个正整数 $a,b$ 满足 $a+b = n$ 且 $LCM( ...
- hdu2049 不容易系列之(4)——考新郎(组合,错排)
题意: n 个数中 m 个数错排的情况个数. 思路: 先从 n 个数中选出 m 个,即 $C_n^m$, 再算出 m 个数的错排数,即 ${f_{\left( m \right)}}$. 错排: 当n ...