100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > jquery选择器_jQuery选择器

jquery选择器_jQuery选择器

时间:2018-12-10 01:24:03

相关推荐

jquery选择器_jQuery选择器

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.

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

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按名称选择 。

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 。

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选择器的一些常见用法。

$(“*”): This jQuery selector selects all elements in the HTML document.$(“ *”):此jQuery选择器选择HTML文档中的所有元素。 $(this): This selector selects the current HTML element.$(this):此选择器选择当前HTML元素。 $(“li:not(.myclass)”): This selector selects all <li> elements that do not have class=”myclass”.$(“ li:not(.myclass)”):此选择器选择所有不具有class =“ myclass”的<li>元素。 $(“p:first”): This selector selects the first <p> element in the document.$(“ p:first”):此选择器选择文档中的第一个<p>元素。 $(“ul li:first”): This selector selects the first <li> element of the first <ul>$(“ ul li:first”):此选择器选择第一个<ul>的第一个<li>元素 $(“ul li:first-child”): This selector selects the first <li> element of every <ul>$(“ ul li:first-child”):此选择器选择每个<ul>中的第一个<li>元素 $(“[href]”): This jQuery selector selects all elements with an href attribute$(“ [href]”):此jQuery选择器选择具有href属性的所有元素 $(“a[target=’_blank’]”): This selector selects all <a> elements with a target attribute value equal to “_blank”$(“ a [target ='_ blank']”):此选择器选择目标属性值等于“ _blank”的所有<a>元素 $(“a[target!=’_blank’]”): This selector selects all <a> elements with a target attribute value NOT equal to “_blank”$(“ a [target!='_ blank']”):此选择器选择目标属性值不等于“ _blank”的所有<a>元素 $(“:button”): This selector selects all <button> elements and <input> elements of type=”button”$(“:button”):该选择器选择所有类型为“ button”的<button>元素和<input>元素 $(“tr:even”): This selector selects all even <tr> elements$(“ tr:even”):此选择器选择所有偶数<tr>元素 $(“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库中的强大机制。 这样可以更轻松地按我们想要的方式处理所有元素。 结合使用选择器,使其功能更强大,更灵活。

翻译自: /4556/jquery-selector

jquery选择器

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。