jquery 中的 $(“#”) 与 js中的document.getElementById(“”) 的区别
来源:互联网 发布:电脑淘宝怎么看上新 编辑:程序博客网 时间:2024/06/06 10:34
以前没注意过,认为jquery 中的 $("#") 与 document.getElementById("") 是一回事,指的是同一个东西。
这次项目开发在使用验证码生成的时候,发现两者不同,使用时需要注意!通过以下测试:
js中代码
function reloadValidCode(o) {
alert(o);
o.src = "${pageContext.request.contextPath }/validCodeServlet?timed=" + new Date().getMilliseconds();
}
function refresh() {
alert($("#imageYZ"));
document.getElementById("imageYZ").src = "${pageContext.request.contextPath }/validCodeServlet?timed=" + new Date().getMilliseconds();
}<img src="${pageContext.request.contextPath }/validCodeServlet" id="imageYZ" alt="换一张" onclick="reloadValidCode(this)"/>
看不清?<a href="#this" onclick="refresh();"> 换一张</a>
我很打算在refresh()函数中使用
$("#imageYz").src = "${pageContext.request.contextPath }/validCodeServlet?timed=" + new Date().getMilliseconds();
进行设置,但是发现不行;原来alert(o)的结果是:
进行设置,但是发现不行;原来alert(o)的结果是:
[object HTMLCanvasElement]
[objec Object]
从这里不难看出两者真的不一样;
从这里不难看出两者真的不一样;
再用firebug调试看一下,
$("#imageYZ")和document.getElementById("imageYZ")倒底是什么内容。调试结果如下:
$("#imageYZ") [img#imageYZ]
document.getElementById("imageYZ") img#imageYZ
想必,看到这里,不用我说,大家也会想到结果了。
实际上,$("#imageYZ")[0]等同于 document.getElementById("imageYZ")
$("#imageYZ")和document.getElementById("imageYZ")倒底是什么内容。调试结果如下:
$("#imageYZ") [img#imageYZ]
document.getElementById("imageYZ") img#imageYZ
想必,看到这里,不用我说,大家也会想到结果了。
实际上,$("#imageYZ")[0]等同于 document.getElementById("imageYZ")
原文地址:http://www.blogjava.net/tyjava/articles/372007.html
阅读全文
0 0
- jquery 中的 $(“#”) 与 js中的document.getElementById(“”) 的区别
- jquery 中的 $(“#”) 与 js中的document.getElementById(“”) 的区别
- jquery 中的 $(“#”) 与 js中的document.getElementById(“”) 的区别
- jquery 中的 $(“#”) 与 js中的document.getElementById(“”) 的区别
- jquery 中的 $(“#”) 与 js中的document.getElementById(“”)细微区别
- jquery中的$("")与原生的document.getElementById("")的区别
- jquery中的 $(#id)与document.getElementById( id )的区别
- jquery 中的 $("#id") 与 document.getElementById("id") 的区别
- jquery中的$("#id")与document.getElementById("id")的区别
- jquery中的$("#id")与document.getElementById("id")的区别
- jquery中的 $(#id)与document.getElementById( id )的区别
- jquery中的$("#id")与document.getElementById("id")的区别
- jquery中的$("#id")与document.getElementById("id")的区别
- jquery中的 $(#id)与document.getElementById( id )的区别
- 【JavaScript】jQuery中的$("#id")与document.getElementById("id")的区别
- jquery 中的 $(“#”) 不等于 js中的document.getElementById(“”)
- jq中的$("#id")与js中的document.getElementById("id")的区别
- jquery中的$(this)和js的document.getElementById(this)的区别
- Fragment:关于Avoid non-default constructors in fragments的错误
- 串口流控制(flow control)
- 序列(sequence)语法
- 初步了解红黑树
- bzoj 4517 [Sdoi2016]排列计数
- jquery 中的 $(“#”) 与 js中的document.getElementById(“”) 的区别
- 亚媒社和亚洲传媒集团的发展,亚洲传媒集团,亚洲传媒集团怎么样,亚洲传媒,亚太传媒
- 2017-6-6(成功搭建服务器)
- 【Linux 系统编程】Xshell 远程连接Linux 服务器
- 排序算法之总纲
- 关于Socket程序中的ntohs, ntohl, htons,htonl
- Tensorflow
- 常见硬件通信协议总结
- SQL语句更新时间字段的年份、月份、天数、时、分、秒