jquery按名稱選擇
jQuery select by name or jQuery element selector allows us to find all HTML elements with the given tag name. You can do any sort of manipulation like animating or any other special effects after selecting the element and that change will take effect in all the elements of the same type or tag name. Earlier we learned using jQuery select by id and jQuery select by class.
jquery innerhtml? jQuery按名稱選擇或jQuery元素選擇器允許我們查找具有給定標簽名稱的所有HTML元素。 選擇元素后,您可以進行任何類型的操作,例如動畫設置或任何其他特殊效果,并且更改將在相同類型或標記名稱的所有元素中生效。 之前我們學習過使用jQuery按id 選擇和按類選擇jQuery 。
Here is the general syntax for using the jQuery select by name:
以下是使用jQuery按名稱選擇的一般語法:
$('tagName')
jquery通過name獲取元素。Any standard HTML elements like div, li, img,? p, em? etc could be used as the tagName
. For example;
任何標準HTML元素(例如div,li,img,p,em等)都可以用作tagName
。 例如;
$('div')
: This element selector will select all the div elements in the document.
jquery name選擇器, $('div')
:此元素選擇器將選擇文檔中的所有div元素。
$('p')
: This jquery select by name will consider all the paragraph elements in the document.
$('p')
:按名稱選擇的此jquery將考慮文檔中的所有段落元素。
jquery復選框。If there are multiple <div> elements, you can change all the <div> elements in the document with this single expression $(‘div’).
如果有多個<div>元素,則可以使用單個表達式$('div')更改文檔中的所有<div>元素。
You can hide, show or do any kind of manipulations on that <div> element. This is the most powerful advantage of using this jQuery selector.
jquery小時選擇器, 您可以在該<div>元素上隱藏,顯示或進行任何類型的操作。 這是使用此jQuery選擇器的最大優勢。
This example demonstrates the use of jQuery select by name of tag, we will change the CSS style of the selected element.
此示例演示了使用jQuery通過標簽名稱進行選擇,我們將更改所選元素CSS樣式。
<html>
<head><title>jQuery selector By Name</title><style>div, span {width: 70px;height: 70px;float: left;padding: 12px;margin: 12px;background-color: #eee;}</style><script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body><div>DIV 1</div>
<span>SPAN 1 </span>
<div>DIV 2</div>
<span>SPAN 2 </span><script>
$( "div" ).css( "border", "5px solid green" );
</script>
</body>
</html>
In this example, you can see the selector $("div")
is selected to change the CSS style. The only change in the code modified all the div elements uniformly. This is the strength of jQuery selector by name.
在此示例中,您可以看到選擇器$("div")
被選中以更改CSS樣式。 代碼中的唯一更改是統一修改了所有div元素。 這就是jQuery選擇器的強項。
Below image shows the output produced by above HTML page.
下圖顯示了以上HTML頁面產生的輸出。
Therefore, in the case of enforcing a uniform behavior on html elements, you can use jQuery select by name in the code.
因此,在對html元素強制執行統一行為的情況下,可以在代碼中使用jQuery按名稱選擇。
翻譯自: https://www.journaldev.com/4552/jquery-select-name
jquery按名稱選擇
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态