【发布时间】:2015-06-25 03:34:18
【问题描述】:
更改主选择后,如何在子选择菜单中添加一次选择选项
问题是每次更改选择选项时都会添加选项
如何让每个主要选择选项只选择一次相关选项
html&php:
<?php
$get_tables=$this->db->query("select * from floor_plan where fp_name='bellevue' and status='available' order by abs(t_id)");
?>
<div class="form-group">
<label for="qtn">Choose Table:</label>
<select name="parent_table" id="table_all_numbers" class="form-control">
<?php
while($each_row=$get_tables->fetch_assoc()){
?>
<option rel="<?php echo $each_row['ava_seats']; ?>" class="<?php echo $each_row['t_name']; ?>" value="<?php echo $each_row['t_id']; ?>">#<?php echo $each_row['t_id']; ?> <?php if($each_row['t_name']=='vip'){echo '$'.$each_row['price']."/Table";}else{echo '$'.$each_row['price']."/Seat";} ?></option>
<?php
}
?>
</select>
</div>
jquery:
var $items = $('select[name=parent_table]');
//quantity
$items.change(function(){
var $this=$(this).find(':selected'),
rel=$this.attr('rel');
for(i=0;i<=rel;i++){
$("#qtn").show();
$("<option value='"+i+"'>"+i+"</option>").appendTo('#qtn');
}
})
【问题讨论】: