0
我的HTML:如何獲得多個跨度的HTML內容,並添加值類
<div class="inside">
<ul class="fourcol first">
<li class="amenity-item">Something: <span>0</span></li>
<li class="amenity-item">Something: <span>0</span></li>
<li class="amenity-item">Something: <span>1</span></li>
<li class="amenity-item">Something: <span>0</span></li>
<li class="amenity-item">Something: <span>1</span></li>
<li class="amenity-item">Something: <span>0</span></li>
<li class="amenity-item">Something: <span>1</span></li>
<li class="amenity-item">Something: <span>1</span></li>
<li class="amenity-item">Something: <span>0</span></li>
</ul>
</div>
我試圖做到:
<div class="inside">
<ul class="fourcol first">
<li class="amenity-item">Something: <span class="amenity-val-0">0</span></li>
<li class="amenity-item">Something: <span class="amenity-val-0">0</span></li>
<li class="amenity-item">Something: <span class="amenity-val-1">1</span></li>
<li class="amenity-item">Something: <span class="amenity-val-0">0</span></li>
<li class="amenity-item">Something: <span class="amenity-val-1">1</span></li>
<li class="amenity-item">Something: <span class="amenity-val-0">0</span></li>
<li class="amenity-item">Something: <span class="amenity-val-1">1</span></li>
<li class="amenity-item">Something: <span class="amenity-val-1">1</span></li>
<li class="amenity-item">Something: <span class="amenity-val-0">0</span></li>
</ul>
</div>
我嘗試:
$(function() {
var value_of_span = $.each('span.amenity-val').html()
if (value_of_span == 0) {
$('span.amenity-val').addClass('amenity-val-0');
}
if (value_of_span == 1) {
$('span.amenity-val').addClass('amenity-val-1');
}
})