我会用代码解释我的情况。
HTML:
<div class="list1">
<select class="select250">
<option class="temp" selected="selected" name="filter[]">Select</option>
<option class="" value="George" name="filter[]">George</option>
<option class="" value="Ben" name="filter[]">Ben</option>
</select>
</div>
<div class="list2">
<select class="select251">
<option class="temp" selected="selected" name="filter[]">Select</option>
<option class="" value="Sarah" name="filter[]">Sarah</option>
<option class="" value="Alex" name="filter[]">Alex</option>
<option class="" value="Natalie" name="filter[]">Natalie</option>
</select>
</div>
<div class="list3">
<select class="select252">
<option class="temp" selected="selected" name="filter[]">Select</option>
<option class="" value="Mobile" name="filter[]">Mobile</option>
<option class="" value="Car" name="filter[]">Car</option>
<option class="" value="Computer" name="filter[]">Computer</option>
</select>
</div>
JS(在 PHP 中使用):
<script type="text/javascript">
$('.select<?php echo $sid?>').change(function() {
$('.temp', this).remove(); // THIS IS FINE
if ($('option').siblings('.temp')) { }
else { $('select').prepend('<option name="filter[]" selected="selected" class="temp">Select</option>'); // THIS IS NOT WORKING
}
});
</script>
What I wanted to do is - whenever an option is selected, it should remove the "Select" option within that list but still keep "Select" option on other lists. 这部分似乎工作正常。接下来要做的是 - 当在另一个列表中选择一个选项时,它应该在所有其他列表上恢复选择,除了它被选择的列表。如您在上面看到的,我尝试为它编写代码,但无法超越它。如果有人能引导我朝着正确的方向前进,那就太棒了。谢谢。