我需要创建一个添加按钮,每次用户按下它时,都会创建一个新的下拉列表,并且选定的值不会在新的dpl中。第一个下拉列表是从数据库中获取数据(这是完成的)。添加按钮,将创建新的下拉列表,并从新的dpl中删除选定的值
我试过这样[示例] [1]但它不起作用!有小费吗?
而且,这是惯例所以不需要验证等等等等
HTML代码
<div id="services-D" class="oneField" >
<label id="services-L" for="services" class="label preField reqMark" style="width: 100px; min-width:0">Services</label><br>
<select id="c_service" name="c_service" class="required dynamic-select" style="width:170px" >
<option value="">Select Service...</option>
<?php
$res=mysqli_query($dbc,"Select t1 t2 Where t4s = 'Y'");
while ($row = mysqli_fetch_array($res)) { ?>
<option value = <?php echo $row['invoice_code']?> > <?php echo $row['t1'] . ": " . $row['t2'];}?> </option>
?>
</select>
</div>
<button type="button" id="btn_add_service" style="">Add Service</button>
jQuery的
<script>
$('#btn_add_service').on('click', function() {
selected = $('#c_service').prop('selectedIndex');
if (selected != 0 && $('#c_service').find('option').length != 2){
newselector = $('<select id="c_service"></select>').insertAfter('#c_service');
$('#c_service').find('option').each(function(index,item) {
if (index != selected){
$(newselector).append(item);
}
});
}
});
</script>
什么'选择value'?请分享一些HTML,JavaScript来举例说明问题。 –
立即查看@AlanLarimer – noel293