如何將類選擇器動態添加到img
標記中。例如: img標籤應該是錨標記,然後只在類名中:樣品應動態取其錨標記包含IMG像添加, 前:使用Jquery動態添加類?
<a href="image.png"><img src="image.png"/></a>
後:
<a href="image.png"><img src="image.png" class="sample"/></a>
如果已經有圖像標籤包含類,那麼刪除該類,新的類可能在jquery中。我不確定,我如何在jQuery中做到這一點。 任何建議都會很棒。
感謝, 玉萍
Just use:['.addClass()'](http://api.jquery.com/addClass/),['.hasClass()'](http://api.jquery.com/hasClass/ )和['.removeClass()'](http://api.jquery.com/removeClass/)。或者使用['.not()'](http://api.jquery.com/not/)而不是'.hasClass()'。 – Joe
看到這個http://stackoverflow.com/questions/5995628/adding-attribute-in-jquery刪除屬性添加removeAttr()之前attr() – L10