我是JQuery中的新手,我需要通過單擊此表中的提交按鈕來選擇單選按鈕,就在JQuery回發函數之前。JQuery:如何通過點擊提交按鈕「選擇」單選按鈕?
我很抱歉,我的代碼專門JQuery的是太多的混亂和業餘愛好者。
<script type="text/javascript"><!--
$('.button-cart').on('click', function() {
btn_id = $(this).attr('id');
qty_id = '#input-quantity' + btn_id.replace('button-cart', '');
input_qty_val = $(qty_id);
$('#input-quantity').val(input_qty_val.val());
radio_id = $(this).closest('input[type=radio]').attr('id');
alert(radio_id);
$.ajax({
url: 'index.php?route=checkout/cart/add',
type: 'post',
data: $('#product input[type=\'text\'], #product input[type=\'hidden\'], #product input[type=\'radio\']:checked, #product input[type=\'checkbox\']:checked, #product select, #product textarea'),
dataType: 'json'
});
});
//--></script>
提交按鈕和無線電輸入在不同的單元格中。
<table>
<tbody>
<tr>
<td><div class="radio">
<label>
<input type="radio" id="option-229-26" name="option[229]" value="26">
70B </label>
</div></td>
<td> 12 </td>
<td><input type="text" name="quantity" value="1" size="2" id="input-quantity-229-26" class="qty form-control"></td>
<td><button type="button" id="button-cart-229-26" data-loading-text="Loading..." class="button-cart btn btn-primary btn-lg btn-block"><i class="fa fa-cart-plus" aria-hidden="true"></i></button></td>
</tr>
<tr>
<td><div class="radio">
<label>
<input type="radio" id="option-229-27" name="option[229]" value="27">
75B </label>
</div></td>
<td> 12 </td>
<td><input type="text" name="quantity" value="1" size="2" id="input-quantity-229-27" class="qty form-control" autocomplete="off"></td>
<td><button type="button" id="button-cart-229-27" data-loading-text="Loading..." class="button-cart btn btn-primary btn-lg btn-block"><i class="fa fa-cart-plus" aria-hidden="true"></i></button></td>
</tr>
</tbody>
</table>
<input type="hidden" name="quantity" id="input-quantity" value="3">
非常有趣!如果你給我更多的細節,特別是HTML和如何檢查單選按鈕,我會很感激。 – Kardo
@Kardo,查看更新回答的代碼片段 –
感謝您花時間幫助我,我真的很感激它! (http://bindexo.com/index.php?route=product/product&product_id=52) – Kardo