我有一个带有单选按钮的表格,在第一列,选项是:
- '---'
- '没有存货'
- '有库存'
在第二列,选项是:
- '---'
- '没有存货'
- '低的'
- '中等的'
- '高的'
现在我要做的是,当用户在第一列上单击“无库存”时,应检查第二列上的“无库存”单选选项。
这就是我正在做的事情:
HTML:
<table border='1'>
<tr>
<td class="valign_top" style="text-align:left;">
<div class="radio_field">
<input type="radio" class="stock_avail" id="93_stock_avail_0" name="93_stock_avail" value="0" checked=""> ---
</div>
<div class="radio_field">
<input type="radio" class="stock_avail" id="93_stock_avail_No" name="93_stock_avail" value="No"> No Stock
</div>
<div class="radio_field">
<input type="radio" class="stock_avail" id="93_stock_avail_Yes" name="93_stock_avail" value="Yes"> With Stock
</div>
</td>
<td class="sa_sw_td valign_top" style="text-align:left;">
<div class="radio_field">
<input type="radio" class="sa_sw" name="93_sa_sw" id="93_sa_sw_0" value="0" checked=""> ---
</div>
<div class="radio_field">
<input type="radio" class="sa_sw" name="93_sa_sw" id="93_sa_sw_1" value="1"> No Stock
</div>
<div class="radio_field">
<input type="radio" class="sa_sw" name="93_sa_sw" id="93_sa_sw_2" value="2"> Low
</div>
<div class="radio_field">
<input type="radio" class="sa_sw" name="93_sa_sw" id="93_sa_sw_3" value="3"> Medium
</div>
<div class="radio_field">
<input type="radio" class="sa_sw" name="93_sa_sw" id="93_sa_sw_4" value="4"> High
</div>
</td>
</tr>
<tr>
<td class="valign_top" style="text-align:left;">
<div class="radio_field">
<input type="radio" class="stock_avail" id="94_stock_avail_0" name="94_stock_avail" value="0" checked=""> ---
</div>
<div class="radio_field">
<input type="radio" class="stock_avail" id="94_stock_avail_No" name="94_stock_avail" value="No"> No Stock
</div>
<div class="radio_field">
<input type="radio" class="stock_avail" id="94_stock_avail_Yes" name="94_stock_avail" value="Yes"> With Stock
</div>
</td>
<td class="sa_sw_td valign_top" style="text-align:left;">
<div class="radio_field">
<input type="radio" class="sa_sw" name="94_sa_sw" id="94_sa_sw_0" value="0" checked=""> ---
</div>
<div class="radio_field">
<input type="radio" class="sa_sw" name="94_sa_sw" id="94_sa_sw_1" value="1"> No Stock
</div>
<div class="radio_field">
<input type="radio" class="sa_sw" name="94_sa_sw" id="94_sa_sw_2" value="2"> Low
</div>
<div class="radio_field">
<input type="radio" class="sa_sw" name="94_sa_sw" id="94_sa_sw_3" value="3"> Medium
</div>
<div class="radio_field">
<input type="radio" class="sa_sw" name="94_sa_sw" id="94_sa_sw_4" value="4"> High
</div>
</td>
</tr>
</table>
JavaScript:
$(document).ready(function(){
$('.stock_avail').click(function(){
var value = $(this).val();
console.log("value: " + value);
if(value=='No'){
$(this).next('td').find('radio').val(2);
}
});
});
这可能会有所帮助:http: //jsfiddle.net/E6mhM/。
任何想法如何做到这一点?蒂亚!!!