0

我有一个带有单选按钮的表格,在第一列,选项是:

  • '---'
  • '没有存货'
  • '有库存'

在第二列,选项是:

  • '---'
  • '没有存货'
  • '低的'
  • '中等的'
  • '高的'

现在我要做的是,当用户在第一列上单击“无库存”时,应检查第二列上的“无库存”单选选项。

这就是我正在做的事情:

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/

任何想法如何做到这一点?蒂亚!!!

4

2 回答 2

1
$(document).ready(function(){
    $('.stock_avail').click(function(){

        var value = $(this).val();
        console.log("value: " + value);

        if(value=='No'){
            $(this).closest("td").next().find("input[value=1]").attr("checked",true);
        }

    });
});​

演示:http: //jsfiddle.net/E6mhM/4/

于 2012-11-19T08:59:35.220 回答
0
$(document).ready(function(){
    $('.stock_avail').click(function(){
        if($(this).val()=='No'){
            $(this).parent().parent().next().find(':radio:eq(1)').attr('checked','checked');
           //assuming No stock will be always a second radio option 
        }
    });
});
于 2012-11-19T09:06:48.957 回答