2013-08-20 21 views

回答

8

的jQuery的等效:

$(".elements").each(function() { 
    // do something with this being one of elements with a 'elements' class 
    // you can access the current element with $(this) 
}); 

是飛鏢:

querySelectorAll('.elements').forEach((Element e) { 
    // do something with e being one of elements with a 'elements' class 
    // you can access the current element with e 
}); 
+0

應當指出的是'e'也可以直接執行類似InputElement任何HTML元素,SpanElement中,的DivElement ...我更喜歡這個,因爲它明確了我正在處理什麼元素 – DrColossos

+0

你的意思是以這種格式使用e而不是這個** e.style.background ** ?? –

+0

是的。當你使用jQuery'each''這個'指向當前元素,'$(this)'給出一個圍繞'this'的jQuery包裝器。在Dart中,你沒有這樣的包裝,但Element的API真的很直接和強大。 –