我有两个HTML选择列表,我想删除列表1中与列表2中的元素类似的所有元素。
<select id="availableLanguages" name="availableSoftwareLanguages" multiple="multiple" size="15">
<option value="AL" label="All Languages">All Languages</option>
<option value="AG" label="Argentina">Argentina</option>
<option value="BU" label="Bulgarian">Bulgarian</option>
<option value="CF" label="Canadian French">CanadianFrench</option>
<option value="C1" label="Cantonese">Cantonese</option>
</select>
<input id="addLanguages" type="button" value=" >> ">
<input id="removeLanguages" type="button" value=" << ">
<select id="selectedLanguages" name="selectedLanguages " multiple="multiple" size="15">
<option value="AL" label="All Languages">All Languages</option>
<option value="AG" label="Argentina">Argentina</option>
<option value="BU" label="Bulgarian">Bulgarian</option>
</select>
所以这里我要删除列表availableLanguages中的选项,这些选项类似于list selectedLanguages中的选项。
答案 0 :(得分:5)
我假设您通过期权价值进行匹配?如果是这样,请尝试:
$("#selectedLanguages option").each(function () {
$("#availableLanguages option[value='" + $(this).val() + "']").remove();
});