我需要創建一個添加按鈕,每次用戶按下它時,都會創建一個新的下拉列表,並且選定的值不會在新的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