这里是我的HTML,其中有两个单选按钮。默认选中的按钮是“租赁”按钮。当您检查单选按钮时触发一个动作
<input
id="quotation_request_payment_option_lease"
class="choose_payment_option"
name="quotation_request[payment_option]"
type="radio"
value="lease"
checked="checked">
<input
id="quotation_request_payment_option_finance"
class="choose_payment_option"
name="quotation_request[payment_option]"
type="radio"
value="finance">
我想要做的是,当租赁按钮被选中时,打印“租赁”到控制台。当检查“财务”时,打印“财务”到控制台。 我试过各种东西都无济于事。
这不起作用:
$(document).ready(function() {
$('input[type=radio[name='quotation_request[payment_option]']').change(function() {
if (this.value == 'lease') {
console.log("lease");
}
else if (this.value == 'finance') {
console.log("finance");
}
});
});
*“默认选中的按钮是”租赁“按钮。”* - 为什么在两个按钮上都选中了checked =“checked”? – nnnnnn
这是一个错字,我的意思是只检查=“检查”的租约按钮 – AliciaGuerra