我有一组顺序下拉列表,这些下拉列表根据前一个下拉列表中的选择进行填充。现在,一旦第三个下拉列表具有<option>
用户选择的值,该值就会添加到它下面的表格中。
我要解决的是,如果用户选择了choice 3
该值,我该如何做到unsure
这一点,在此之后,如果用户然后选择 for choice 1
,unsure
也unsure
将被删除choice 3
?因此,最新的选择将覆盖任何其他choice
具有相同值的输入到表中。表格中不能输入任何两个相同的值。
HTML:
<form method="POST">
<select name='first' id='first'>
<option selected="selected" value="nothing">choose</option>
<option value='opt_a'>opt a</option>
</select>
<select name='sec' id='sec'>
</select>
<select name='third' id='third'>
</select>
<br />
<br />
<div id="result">
<table>
<tr>
<th>category</td>
<th>choice</td>
</tr>
<tr>
<td>choice 1</td>
<td></td>
</tr>
<tr>
<td>choice 2</td>
<td></td>
</tr>
<tr>
<td>choice 3</td>
<td></td>
</tr>
<tr>
<td>choice 4</td>
<td></td>
</tr>
</table>
</div>
</form>
JS:
data = {
opt_a: ['choose_1','choose_2','choose_3','choose_4'],
choose_1: ['yes','no','unsure','still unsure'],
choose_2: ['yes','no','unsure','still unsure'],
choose_3: ['yes','no','unsure','still unsure'],
choose_4: ['yes','no','unsure','still unsure']
}
$('#first').change(function(){
var firstopts = ''
$.each(data[$(this).val()],function(i,v){
firstopts += "<option value='"+v+"'>"+v+"</option>"
})
$('#sec').html(firstopts)
})
$('#sec').change(function(){
var secopts = ''
$.each(data[$(this).val()],function(i,v){
secopts += "<option value='"+v+"'>"+v+"</option>"
})
$('#third').html(secopts)
})
$('#third').change(function() {
$('table tr').filter(function() {
var number1 = $('#sec').val().split('_')[1];
var number2 = $(this).find('td:eq(0)').text().split(' ')[1];
return number1 == number2;
}).find('td:eq(1)').text($(this).val());
});
提前感谢您的帮助。