2014-05-09 38 views
0

我想知道在jQuery中獲取對象的所有這些方法之間的真正區別是什麼。jQuery選擇器之間的區別,查找並獲取

  1. $('[id*="partofthename"]')
  2. $('#name')
  3. $find('id_of_control')
  4. $get('id_of_control')

我做了一些研究,我發現:

  1. 這裏您可以看到由控制正道其ID,但它是第四與2和4相同。對嗎?
  2. 第二個是4號的shorcut。$get。不是嗎?
  3. $find越來越有屬性和方法
  4. $get對象是一樣的document.getElementById()

現在的數字3和4真不小。 與$find$get都給我的對象。 $find是.NETs findComponent()功能

$get & $find是快捷功能微軟已經內置到他們的Ajax JavaScript庫。

但是,當我們談論DOM元素和javascript對象。

+0

我已經刪除了關於推薦JavaScript書的部分。建議是堆棧溢出的主題。 – Matt

+0

我想你必須澄清一點,jQuery中沒有'$ find'或'$ get',有'.find()'和'.get()',它們甚至不能做到遠程相同的東西?你似乎在比較蘋果和橘子,一些jQuery的東西,一些微軟的東西,然後som .NET功能? – adeneo

+0

@ adeneo,謝謝你的回覆。這就是爲什麼我問,因爲我真的是新的。如果你可以澄清那會很棒。 –

回答

2

1。 $('[id*="partofthename"]')選擇零/單/多元件id包含partofthename

Attribute Contains Selector文檔:

Selects elements that have the specified attribute with a value containing the a 
given substring. 

2。 $('#name')id選擇單個元素= name

ID Selector文檔:

Selects a single element with the given id attribute. 

3。 $.find('id_of_control')選擇使用濾波器id_of_control

元件的所有後代從.find()文檔:

Get the descendants of each element in the current set of matched elements, 
filtered by a selector, jQuery object, or element. 

4。 $.get('id_of_control')選擇由jQuery對象ie匹配的匹配元素之一。,id_of_control

.get()文檔:

Retrieve one of the elements matched by the jQuery object. 
0
  1. 是拼寫2.緩慢的方式,絕對不是通過ID獲取元素

  2. 的正確方法是jQuery的方式通過編號獲得元素

  3. 和4.是ASP.Net應用程序中MS特定的API,4.應該b (除非你沒有得到一個jQuery對象,你會得到一個MSAL DomElement對象)