jquery选择器

jQuery selector is the most significant element in the jQuery library. The main tasks we do in the jQuery are selecting DOM elements and manipulate the elements to carry out the intended actions.

jQuery选择器是jQuery库中最重要的元素。 我们在jQuery中所做的主要任务是选择DOM元素并操纵这些元素以执行预期的操作。

jQuery选择器 (jQuery selector)

jQuery selector allows us to search and control HTML elements.

jQuery选择器使我们可以搜索和控制HTML元素。

We can do this in three ways.

我们可以通过三种方式做到这一点。

  1. jQuery select by tag name

    Syntax: $('html_tag_name')

    This will select all the HTML elements with the tag name. For example $(‘p’) will select all the paragraphs in the DOM. Further reading: jQuery select by name.

    jQuery按标签名称选择

    语法: $('html_tag_name')

    这将选择所有带有标签名称HTML元素。 例如$('p')将选择DOM中的所有段落。 进一步阅读: jQuery按名称选择 。

  2. jQuery select by ID

    Syntax: $("#ID_of_Element")

    This will select an element with this id from the DOM. For Example, if there is an element in the DOM like

     <div id=’text’>This is text </div>.

    We can hide, show, toggle or make any manipulations of the text by selecting the element by its id ‘text’ as $(“#text”). More details are at jQuery select by id.

    jQuery按ID选择

    语法: $("#ID_of_Element")

    这将从DOM中选择一个具有此ID的元素。 例如,如果DOM中有一个元素,例如

    <div id ='text'>这是文本</ div>

    我们可以通过选择其ID为'text'的元素作为$(“#text”)来隐藏,显示,切换或对文本进行任何操作。 更多详细信息在jQuery select by id 。

  3. jQuery select by class
    Syntax: $(".classname")

    This will select all elements in the DOM with the specified class name.

    After the selection of elements, we will have complete control over that component and it could be manipulated in the way we desire to build the web page. Refer more at jQuery select by class.

    jQuery按类别选择
    语法: $(".classname")

    这将选择DOM中具有指定类名的所有元素。

    选择元素之后,我们将完全控制该组件,并且可以按照我们希望构建网页的方式对其进行操作。 请参阅jQuery select by class的更多内容 。

jQuery选择器语法 (jQuery selector syntax)

jQuery selector is always preceded by $. jQuery() is a synonym for $(). You can use jQuery() function if the dollar sign conflicts with any other JavaScript functions.

jQuery选择器始终以$开头。 jQuery()是$()的同义词。 如果美元符号与任何其他JavaScript函数冲突,则可以使用jQuery()函数。

All the mentioned selectors can be used alone or combined with other selectors.

所有提到的选择器可以单独使用,也可以与其他选择器组合使用。

jQuery选择器示例 (jQuery selector example)

Let’s look at some common usage of jQuery selector.

让我们看一下jQuery选择器的一些常见用法。

  1. $(“*”): This jQuery selector selects all elements in the HTML document.$(“ *”):此jQuery选择器选择HTML文档中的所有元素。
  2. $(this): This selector selects the current HTML element.$(this):此选择器选择当前HTML元素。
  3. $(“li:not(.myclass)”): This selector selects all <li> elements that do not have class=”myclass”.$(“ li:not(.myclass)”):此选择器选择所有不具有class =“ myclass”的<li>元素。
  4. $(“p:first”): This selector selects the first <p> element in the document.$(“ p:first”):此选择器选择文档中的第一个<p>元素。
  5. $(“ul li:first”): This selector selects the first <li> element of the first <ul>$(“ ul li:first”):此选择器选择第一个<ul>的第一个<li>元素
  6. $(“ul li:first-child”): This selector selects the first <li> element of every <ul>$(“ ul li:first-child”):此选择器选择每个<ul>中的第一个<li>元素
  7. $(“[href]”): This jQuery selector selects all elements with an href attribute$(“ [href]”):此jQuery选择器选择具有href属性的所有元素
  8. $(“a[target=’_blank’]”): This selector selects all <a> elements with a target attribute value equal to “_blank”$(“ a [target ='_ blank']”):此选择器选择目标属性值等于“ _blank”的所有<a>元素
  9. $(“a[target!=’_blank’]”): This selector selects all <a> elements with a target attribute value NOT equal to “_blank”$(“ a [target!='_ blank']”):此选择器选择目标属性值不等于“ _blank”的所有<a>元素
  10. $(“:button”): This selector selects all <button> elements and <input> elements of type=”button”$(“:button”):该选择器选择所有类型为“ button”的<button>元素和<input>元素
  11. $(“tr:even”): This selector selects all even <tr> elements$(“ tr:even”):此选择器选择所有偶数<tr>元素
  12. $(“tr:odd”): This selector selects all odd <tr> elements$(“ tr:odd”):此选择器选择所有奇数<tr>元素

jQuery selectors are a powerful mechanism in the jQuery library. This makes it easier to work with all the elements in the way we want. Using selectors in combination makes it even more powerful and flexible.

jQuery选择器是jQuery库中的强大机制。 这样可以更轻松地按我们想要的方式处理所有元素。 结合使用选择器,使其功能更强大,更灵活。

翻译自: https://www.journaldev.com/4556/jquery-selector

jquery选择器

jquery选择器_jQuery选择器相关推荐

  1. jsp层级选择器_jQuery 选择器

    1.基本选择器$("#id") //ID选择器 $("div") //元素选择器 $(".classname") //类选择器 $(&quo ...

  2. jquery name选择器_jquery笔记

    jQuery 是一个封装好的特定的集合(方法和函数).是一个库,封装了很多预先定义好的函数在里面. 概念 jQuery是一个快速,简洁的js库. j是js,query是查询,把js中的DOM操作作了封 ...

  3. jquery选择器连续选择_jQuery选择器简介

    您可能已经知道, CSS3引入了一组新的选择器,使我们能够在添加HTML类较少的情况下选择文档中的元素 . 但是,新CSS选择器依赖于浏览器的功能,因此在某些情况下不适用. jQuery有一组选择器, ...

  4. 转:初探 jQuery 的 Sizzle 选择器

    这是一篇关于介绍jQuery Sizzle选择器的文章,由我和obility共同完成.在文中,我们试图用自己的语言配以适量的代码向读者展现出Sizzle在处理选择符时的流程原理,以及末了以少许文字给你 ...

  5. jQuery九类选择器

    jQuery选择器基本选择器 #id/标签名/样式名/选择器A,选择器B jQuery层次选择器 *form input:查询form下所有input元素,含有后代关系 form>input:查 ...

  6. jq查找字段忽略html标签,jquery内容过滤选择器有哪些?

    jQuery内容过滤选择器的过滤规则主要运用在DOM元素所包含的子元素或其文本内容上,主要包括四种过滤方法: :contains(text).:empty .:has(seletor) .:paren ...

  7. webform(九)——JQuery基础(选择器、事件、DOM操作)

    JQuery -- 一个js函数包 一.选择器 1.基本选择器 ①id选择器:#       ②class选择器:.       ③标签名选择:标签名 ④并列选择:用,隔开          ⑤后代选 ...

  8. jquery常见的选择器

    jquery常见的选择器 具体参考官方API:http://jquery.cuishifeng.cn/ 1. 基本选择器 1.通配符选择器 * 用于选择所有元素2.元素选择器 选择文档的元素 如htm ...

  9. 重磅推荐12款jQuery编写的选择器

    我最近开始编写自己的jQuery选择器,我越来越开始意识到这是一种不错而简洁的完成某些特定任务的方式,而以往我使用的是迭代器. 这些选择器中如果不是你一直在寻找的,你也许根本将不会碰到.所以我决定写下 ...

最新文章

  1. uml 时序图_设计模式:UML是怎么回事?设计原则?
  2. LMDB中的mmap、Copy On Write、MVCC深入理解——讲得非常好,常来看看!
  3. [译] 常用 Phpstorm tips (下/共3部分)
  4. 任务切换——《x86汇编语言:从实模式到保护模式》读书笔记38
  5. scenejs的一点Cameras小笔记
  6. JAVA笔记:死锁的详细解释
  7. 软RAID-mdadm折腾小记
  8. linux 硬盘繁忙,icinga2 借助check_iostat.sh抓取linux服务器的diskIO(硬盘繁忙度)
  9. 【Python】python3编码方式encode介绍
  10. 作者:姚登举(1980-),男,哈尔滨理工大学副教授。
  11. Oracle分析函数-nulls first/nulls last
  12. 在磁盘上给文件快速预留一大片空间
  13. 拓端tecdat|用R语言实现神经网络预测股票实例
  14. JAVA调起clearcase_Rational ClearCase和Rational ClearQuest对Java API的支持
  15. ngod规范_[转载]NGOD一些感悟
  16. Android简单闹钟设置
  17. Redis源码解读(七)——基本类型—dict
  18. TIFF图像文件(四):LZW压缩
  19. 嵌入式开发需要学习哪些东西
  20. 用友远程命令执行漏洞并提权

热门文章

  1. spring 连数据库的配置文件
  2. 怎样设置HTML上传控件,上传文件的大小
  3. [转载] Python字符串操作大全(一)
  4. [转载] Python:Numpy详解
  5. python3+xlrd解析Excel
  6. Java调用Javascript、Python算法总结
  7. Python 模块安装失败
  8. 一个用户故事的样例(极限编程)
  9. CS229-Lesson7最优间隔分类器
  10. visual studio 删除附加项