我有以下用于删除重复列表项的 jQuery 代码。有更好/更快的方法吗?http://jsfiddle.net/Lijo/Hb28u/16/
HTML
<div style="width: 100px">
<ul>
<li style="background-color: Red">A</li>
<li style="background-color: Red">B</li>
<li style="background-color: Orange">B</li>
<li style="background-color: Red">C</li>
<li style="background-color: Orange">C</li>
<li style="background-color: Yellow">C</li>
<li style="background-color: Red">D</li>
</ul>
</div>
<input id="Submit1" type="submit" value="submit" class="submitButton" />
jQuery
$('.submitButton').click(function (e) {
alert('Begin');
var previousVal = 'Initial';
$('ul li').each(function (i, item) {
var currentVal = $(item).text();
if (currentVal == previousVal) {
$(item).remove();
}
previousVal = currentVal;
});
alert('End');
return false;
}
);