获取流星中自定义Bootbox字段的值
问题描述:
我想打开带有多个输入字段的Bootbox对话框,并且从前面的答案中可以看出,我只能提供包含输入字段的html代码的消息。但是,当我尝试在回调函数中检索其中一个字段的值时,我一直未定义。我如何检索和存储放入这些字段的数据?获取流星中自定义Bootbox字段的值
Template.newUser.events({
'click' : function() {
bootbox.dialog({message:"<form id='infos' method='get' action=''>\
<input type='text' name='phone' placeholder='Phone Number'/><br>\
<input type='text' name='pin' placeholder='PIN' /><br>\
<input type='text' name='code' placeholder='Verification Code' />\
</form>",
title: "Register",
buttons: {
Register: {
label: "Register",
className: "btn-register",
callback: function() {
var code = $('#phone').value;
console.log(code);
return true;
}
}
}
}
});
答
您尝试选择与'phone'
,$('#phone').value
ID输入。尝试将<input type='text' name='phone' placeholder='Phone Number'/>
更改为<input type='text' id='phone' name='phone' placeholder='Phone Number'/>