当我在Meteor中有一个带有两个单选按钮的表单时,第一个值总是在.val()调用中返回。访问哪个单选按钮的正确方法是什么?
以下是我的示例代码:
testRadioButtons.html:
<template name="testRadioButtons">
<form class="main">
<div class="control-group">
<div class="controls">
<input name="insuranceDecision" type="radio" value="NoInsurance"/>   Don't Buy Insurance<br><br>
<input name="insuranceDecision" type="radio" value="BuyInsurance"/>   Buy Insurance<br><br>
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="submit" value="Submit" class="btn btn-primary"/>
</div>
</div>
</form>
</template>
testRadioButtons.js
Template.testRadioButtons.events({
'submit form': function(e) {
e.preventDefault();
console.log('running form submit')
decision = $(e.target).find('[name=insuranceDecision]').val();
// console.log($(e.target).find('[name=insuranceDecision]'));
console.log("decision: " + decision); // ZZZZZ Why is NoInsurance always displaying, even when the other radio button is checked.?
Meteor.Router.to('happyPage');
}
});
以下是需要我写的东西,但没有做任何重要的事情。 main.html中
<head>
<title>testRadioButtons</title>
</head>
<body>
{{renderPage}}
</body>
router.js
Meteor.Router.add({
'/': 'testRadioButtons',
'/happyPage' : 'happyPage'
})
happyPage.html
<template name="happyPage">
<p> Happy page </p>
<p><a href={{testRadioButtonsPath}}>Test Radio Buttons Again</a></p>
</template>