(3)选择元素——(3)$()方法(The $() function)
No matter which type of selector we want to use in jQuery, we always start with the same function: $(). This function typically accepts a CSS selector as its sole parameter, and serves as a factory, returning a new jQuery object pointing to the corresponding elements on the page. Just about anything that can be used in a stylesheet can also be passed as a string to this function, allowing us to apply jQuery methods to the matched set of elements.
无论我们想在jquery中使用哪种类型的选择器,我们总是使用相同的函数$()开头。这个函数典型的接受一个css选择器作为他的基础的元素,然后作为一个工厂放回一个指向网页上相应元素的的新的jquery对象。任何能被样式表使用的东西都可以作为字符串传递给这个方法,允许我们把jquery方法应用到匹配的元素上。
Making jQuery play well with other JavaScript librariesIn jQuery, the dollar sign $is simply an "alias" for jQuery. As a $()function is very common in JavaScript libraries, conflicts could arise if more than one of these libraries were being used in a given page. We can avoid such conflicts by replacing every instance of $with jQueryin our custom jQuery code. Additional solutions to this problem are addressed in Chapter 10, Advanced Events.
The three primary building blocks of selectors are tag name, ID, and class. They can be used either on their own or in combination with others. The following simple examples illustrate how these three selectors appear in code:
三种基本的选择器构建元素分别是tag name ckass和id他们可以单独使用,也可以和其他结合起来使用。下面的简单的例子说明了这三个选择器如何在代码中呈现的。
As mentioned in Chapter 1, Getting Started, when we call methods of a jQuery object, the elements referred to by the selector we passed to $()are looped through automatically and implicitly. Therefore, we can usually avoid explicit iteration, such as a forloop, that is so often required in DOM scripting.
正如第一章:入门指南中介绍的那样,当我们调用jquery对象的方法的时候,我们传递给$()的选择器选中的对象将会自动隐式的循环。因此我们通常可以避免通常在DOM脚本中需要的显式调用。
Now that we have covered the basics, we're ready to start exploring some more powerful uses of selectors.
现在我们已经讲述过了基础知识,我们准备好了去开始探索一些更加高级的选择器的使用。
(3)选择元素——(3)$()方法(The $() function)的更多相关文章
- Extjs 选择元素涉及方法总结
本文主要是解释Extjs在使用过程中使用的相关选择方法: 1.首先解释第一组概念: Ext.get(String/HTMLElement/Ext.Element el) Ext.getCmp(Stri ...
- jQuery选择元素的方法大全
jQuery选择器其实是一个有些地方比较费解的,如果没有经过多次实验的话,很难得出它的每个操作符到底是干什么的,很容易出错,经过 我的多次测试,终于对一些比较难理解或容易出错的选择操作进行总结,既方便 ...
- JQuery中选择元素的方法:
document.getElementById('div1');document.getElementsByTagName('div');getByClass(document,'box'); $(' ...
- Selenium(二):选择元素的基本方法
1. 选择元素的基本方法 对于百度搜索页面,如果我们想自动化输入爱编程的小灰灰,怎么做呢? 这就是在网页中,操控界面元素. web界面自动化,要操控元素,首先需要选择界面元素 ,或者说定位界面元素 就 ...
- D3.js 其他选择元素方法
在上一节中,已经讲解了 select 和 selectAll,以及选择集的概念.本节具体讲解这两个函数的用法. 假设在 body 中有三个段落元素: <p>Apple</p> ...
- 抛弃jQuery:DOM API之选择元素
原文链接:http://blog.garstasio.com/you-dont-need-jquery/selectors/ 我的Blog:http://cabbit.me/you-dont-need ...
- Jquery 系列(2) 选择元素
Jquery基础学习 jQuery利用css选择符的能力,能够在DOM中快捷而轻松地获取元素. 主要内容如下: 介绍DOM树 如何通过CSS选择符在页中查找元素 扩展jQuery标准的CSS选择符 选 ...
- 【 D3.js 入门系列 --- 2 】 如何使用数据和选择元素
接着上一讲的内容,这次讨论如何选择元素和使用数据. 现在页面中有三行文字,代码为: <p>Hello World 1</p> <p>Hello World 2 ...
- JavaScript:JavaScript中常见获取对象元素的方法
介绍: javascript中常见的3种获取元素的方法,分别是通过元素ID.通过标签名字和通过类名字来获取 操作如下: 1.getElementById DOM提供了一个名为getElementByI ...
- JQuery基础教程:选择元素(中)
自定义选择符 JQuery在各种CSS选择符的基础上还添加了独有的完全不同的自定义选择符,注意,只要可能,jQuery就会使用浏览器原生的DOM选择符引擎去查找元素.但在使用自定义选择符的时候,就无法 ...
随机推荐
- Arcgis for javascript不同的状态下自己定义鼠标样式
俗话说:爱美之心.人皆有之. 是的.没错,即使我仅仅是一个做地图的,我也希望自己的地图看起来好看一点. 在本文,给大家讲讲在Arcgis for javascript下怎样自己定义鼠标样式. 首先.说 ...
- Android导航栏ActionBar的具体分析
尊重原创:http://blog.csdn.net/yuanzeyao/article/details/39378825 关于ActionBar,相信大家并不陌生,可是真正能够熟练使用的也不是许多,这 ...
- SharePoint 2007 (MOSS/WSS) - how to remove "Download a Copy" context menu from a Document Library
One of my friend and colleague asked me this question. I found it tricky and a good post for my blog ...
- 关于new Function使用以及将json格式字符串转化为json对象方法介绍
一直对Function()一知半解,今日就Function()的使用做一下总结 一.函数实际是功能完整的对象,用Fucntion()直接创建函数. 语法规则: var 函数名 = new Fun ...
- 深入理解 IE haslayout
转载自Bubblings Blog 原文地址:http://riny.net/2013/haslayout/ 1.什么是haslayout layout是windows IE的一个私有概念,它决定了元 ...
- zen-coding for notepad++,前端最佳手写代码编辑器
zen-Coding是一款快速编写HTML,CSS(或其他格式化语言)代码的编辑器插件,这个插件可以用缩写方式完成大量重复的编码工作,是web前端从业者的利器. zen-Coding插件支持多种编辑器 ...
- Objective-c 内存管理
与 C 有一点类似,oc 需要使用 alloc 方法申请内存.不同的是,c 直接调用 free 函数来释放内存,而 oc 并不直接调用 dealloc 来释放.整个 oc 都使用对象引用,而且每一 ...
- News feed
1. Level 1.0 Database Schema: a. User UserID Name Age 1 Jason 25 2 Michael 26 b. Friendship Friendsh ...
- BZOJ 2821: 作诗(Poetize)( 分块 )
分块,分成N^0.5块.O(N^1.5)预处理出sm[i][j]表示前i块中j的出现次数, ans[i][j]表示第i~j块的答案. 然后就可以O(N^0.5)回答询问了.总复杂度O((N+Q)N^0 ...
- Struts学习之自定义结果集
转自:http://blog.csdn.net/hanxuemin12345/article/details/38763057 项目中我们经常遇到这样的需求——页面部分刷新,例如:添加用户,转到添加用 ...