带有组合框生成功能的代码(运行良好)
<script>
$('#combos').on('change', '.combo', function() {
var selectedValue = $(this).val();
if (selectedValue !== '' && $(this).find('option').size() > 2) {
var newComboBox = $(this).clone();
var thisComboBoxIndex = parseInt($(this).attr('data-index'), 10);
var newComboBoxIndex = thisComboBoxIndex + 1;
$('.parentCombo' + thisComboBoxIndex).remove();
newComboBox.attr('data-index', newComboBoxIndex);
newComboBox.attr('id', 'combo' + newComboBoxIndex);
newComboBox.addClass('parentCombo' + thisComboBoxIndex);
newComboBox.find('option[value="' + selectedValue + '"]').remove();
$('#combos').append(newComboBox);
}
});</script>
html 和 php(运行良好)
<form id="myForm">
<div id="combos"><select id="combo1" class="combo" data-index="1">
<option></option>
<?php
while($r = mysql_fetch_array($result))
{
echo "<option value=\"" .$r['id'] . "\">".$r['field'] ." ------</option>";
}
?>
</select>
</div>
<input type="button" id="button_submit" value="Show">
</form>
此代码应仅选择未选择的组合框。但不工作。我认为仅适用于该函数找到的第一个非选定值。 请看图片
<script>
$('#button_submit').click(function()
{
var combo_box_values = $('#combo1 option:not(:selected)').map(function ()
{
return parseInt(this.value);
}).get();
});
</script>
问:有可能吗?我的代码在哪里丢失?
干杯
编辑:源代码
<h4>Data Options</h4></center>
<div id="combos"><select id="combo1" class="combo" data-index="1">
<option></option>
<option value="1">uptime ------</option>
<option value="2">score ------</option>
<option value="3">gender ------</option>
<option value="4">age ------</option>
<option value="5">angry ------</option>
<option value="6">happy ------</option>
<option value="7">sad ------</option>
<option value="8">surprised ------</option>
<option value="9">location ------</option></select>
<select id="combo2" class="combo parentCombo1" data-index="2">
<option></option>
<option value="1">uptime ------</option>
<option value="2">score ------</option>
<option value="4">age ------</option>
<option value="5">angry ------</option>
<option value="6">happy ------</option>
<option value="7">sad ------</option>
<option value="8">surprised ------</option>
<option value="9">location ------</option></select>
<select id="combo3" class="combo parentCombo1 parentCombo2" data-index="3">
<option></option>
<option value="1">uptime ------</option>
<option value="4">age ------</option>
<option value="5">angry ------</option>
<option value="6">happy ------</option>
<option value="7">sad ------</option>
<option value="8">surprised ------</option>
<option value="9">location ------</option></select>
<select id="combo4" class="combo parentCombo1 parentCombo2 parentCombo3" data-index="4">
<option></option>
<option value="1">uptime ------</option>
<option value="5">angry ------</option>
<option value="6">happy ------</option>
<option value="7">sad ------</option>
<option value="8">surprised ------</option>
<option value="9">location ------</option></select></div>