Meteor 使用template.find获取radiobutton值
我想使用Meteor 使用template.find获取radiobutton值,meteor,Meteor,我想使用template.find(在Templates.xxx.events中)获取radiobutton组的选中radiobutton的值。在jquery中,我将使用$('input:radio[name=XXXXX]:checked').val()。这不适用于模板。查找template.find('input:radio[name=XXXXX]:checked')返回null 对于此任务,我应该使用什么作为CSS选择器?您的选择器看起来不错,因此它可能正是您调用它的方式。也许这个例子会有帮
template.find
(在Templates.xxx.events中)获取radiobutton组的选中radiobutton的值。在jquery中,我将使用$('input:radio[name=XXXXX]:checked').val()
。这不适用于模板。查找template.find('input:radio[name=XXXXX]:checked')
返回null
对于此任务,我应该使用什么作为CSS选择器?您的选择器看起来不错,因此它可能正是您调用它的方式。也许这个例子会有帮助:
html
在这里,我仍然使用jquery来提取值,但它演示了选择器的工作。您的选择器看起来很正确,因此它可能就是您调用它的方式。也许这个例子会有帮助:
html
在这里,我仍然使用jquery提取值,但它演示了选择器的工作。好的,它现在正在工作。老实说,我想我忘了为radiobutton提供默认选中选项:)谢谢!好的,现在开始工作了。老实说,我想我忘了为radiobutton提供默认选中选项:)谢谢!
<template name="animals">
<form>
<input type="radio" name="animal" value="cat">Cat<br>
<input type="radio" name="animal" value="dog">Dog<br>
<input type="button" value="Click">
</form>
</template>
Template.animals.events({
'click :button': function(event, template) {
var element = template.find('input:radio[name=animal]:checked');
console.log($(element).val());
}
});