哪个是使用jquery获取dom的更好方法? [英] which is better way to fetch dom using jquery ?

查看:68
本文介绍了哪个是使用jquery获取dom的更好方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1.    $("#<%=imgDefected.ClientID%>").attr("src", "../images/open.gif");

2. var fileinput = document.getElementById('<%=FileUploader.ClientID%>');







还有其他像id选择器元素选择器。这有什么区别...最好在jquery中使用




There are also other like id selector element selector .. what is the difference in all this .. which is better to use in jquery

推荐答案

(#<% = imgDefected.ClientID %> )。attr(src,../ images / open.gif);

2. var fileinput = document.getElementById('<% = FileUploader.ClientID % > ');
("#<%=imgDefected.ClientID%>").attr("src", "../images/open.gif"); 2. var fileinput = document.getElementById('<%=FileUploader.ClientID%>');







还有其他像id选择器元素选择器。这有什么不同...哪个更适合在jquery中使用




There are also other like id selector element selector .. what is the difference in all this .. which is better to use in jquery


对于#1,我看不到你在比较什么。这已经是jQuery,合理使用。



#2?最好使用jQuery,在这种情况下,是的, id 选择器。区别在于返回了不同的对象:如果是选择器,你有一个DOM元素的 jQuery包装器,它提供了对所有常规DOM元素属性+许多jQuery好东西的访问。要查看包装器的方法,请扫描所有jQuery API。大多数jQuery方法都是选择器返回的包装器的成员方法。



一个与 id 选择器。由于属性 id 应该是唯一的,因此这个包装器是有限的:它只是一个元素的包装器。其他选择器可以在整个DOM元素集上返回 sets 包装器,因此您可以遍历该集合。



-SA
As to #1, I don't see what you are comparing with. This is already jQuery, used reasonably.

#2? It's better to use jQuery, in the case, yes, idselector. The difference is different object returned: in case if selector, you got a jQuery wrapper of the DOM element, which provides access to all regular DOM element properties + many jQuery goodies. To see the methods of the wrapper, scan all the jQuery API. Most of the jQuery methods are the member methods of the wrappers returned by the selector.

One important note related to id selector. As the attribute id is supposed to be unique, this wrapper is limited: it is a wrapper over just one element. Other selectors can return sets wrappers over the whole set of DOM elements, so you can, say, traverse the set.

—SA


这篇关于哪个是使用jquery获取dom的更好方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆