jQuery .wrap和.wrapAll有什麼區別?他們幾乎做同樣的事情,但有什麼區別?jQuery wrap和wrapAll之間的區別
15
A
回答
30
通知中的描述的區別:
.wrap()
:在所述一組匹配元素的環繞式一個HTML結構中的每個元素。.wrapAll()
:在匹配元素集合中圍繞所有元素包裝HTML結構。
.wrap()
單獨包裝每個元素,但.wrapAll()
將所有元素包裝爲一個組。
例如:
<div class="foo"></div>
<div class="foo"></div>
<div class="foo"></div>
隨着$('.foo').wrap('<div class="bar" />');
,出現這種情況:
<div class="bar"><div class="foo"></div></div>
<div class="bar"><div class="foo"></div></div>
<div class="bar"><div class="foo"></div></div>
但隨着$('.foo').wrapAll('<div class="bar" />');
,出現這種情況:
<div class="bar">
<div class="foo"></div>
<div class="foo"></div>
<div class="foo"></div>
</div>
2
WrapAll包裝所有元件,環繞包裹每個元素。
$('.inner').wrapAll('<div class="new" />');
結果在...... EACH元素包裹在一個新的div ALL內的div
<div class="container">
<div class="new">
<div class="inner">Hello</div>
<div class="inner">Goodbye</div>
</div>
</div>
裹結果
<div class="container">
<div class="new">
<div class="inner">Hello</div>
</div>
<div class="new">
<div class="inner">Goodbye</div>
</div>
</div>
0
Adding jquery to execute a wrap:
$(‘p’).wrap(‘<span class=」newclass」 />’);
will result in:
<span class=」newclass」>
<p>This is a paragraph.</p>
</span>
<span class=」newclass」>
<p>This is a paragraph.</p>
</span>
<span class=」newclass」>
<p>This is a paragraph.</p>
</span>
Substitute the .wrap for .wrapAll.
$(‘p’).wrapAll(‘<span class=」newclass」 />’);
will result in:
<span class=」newclass」>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</span>
Now try out .wrapInner.
$(‘p’).wrapInner(‘<span class=」newclass」 />’);
will result in:
<p><span class=」newclass」>This is a paragraph.</span></p>
<p><span class=」newclass」>This is a paragraph.</span></p>
<p><span class=」newclass」>This is a paragraph.</span></p>
相關問題
- 1. jQuery - '。'之間的區別和「#」
- 2. $ wrap函數和getElementById之間的任何區別?
- 3. jquery-rails和jquery-ujs之間的區別
- 4. jQuery中的$和$()之間的區別
- 5. jquery ajax頭和beforesend之間的區別
- 6. HTML5和jQuery之間的區別
- 7. jQuery Mobile和PhoneGap之間的區別
- 8. mousedown和點擊jquery之間的區別
- 9. Backbone.js和jquery之間的區別
- 10. js,jquery和Ajax之間的區別
- 11. Zepto和jQuery之間的區別
- 12. Prototype 1.6和jQuery 1.4.2之間的區別
- 13. Ajax和jQuery-Ajax之間的區別
- 14. jquery $('#my_id')和document.getElementById('my_id')之間的區別?
- 15. addEventListener和jquery之間的區別?
- 16. JS onclick和jQuery之間的區別.click
- 17. JQuery JTable - data.row和data.record之間的區別
- 18. 對象之間的區別(javascript和jquery)
- 19. 之間的〜/和的區別../
- 20. '#','%'和'$'之間的區別
- 21. {!!之間的區別!!}和{{}}
- 22. '+ ='和'= +'之間的區別?
- 23. 「。+」和「。+?」之間的區別
- 24. .eq之間的區別。和==
- 25. #。/和#之間的區別。 ./
- 26. !=和!之間的區別==
- 27. 「%〜dp0」和「。\」之間的區別?
- 28. | =和^ = css之間的區別
- 29. 之間的區別。和#
- 30. ==和case之間的區別?
如果你足夠聰明的寫作,你可能足夠聰明的閱讀。在這裏,你去:http://api.jquery.com/wrap/ http://api.jquery.com/wrapAll/ – ahren 2012-08-14 05:46:35
只是相當熱衷 – 2013-05-06 09:10:31