Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript meteor中一页上多个表单的事件_Javascript_Html_Forms_Meteor - Fatal编程技术网

Javascript meteor中一页上多个表单的事件

Javascript meteor中一页上多个表单的事件,javascript,html,forms,meteor,Javascript,Html,Forms,Meteor,在我的home.html页面中,我有两个表单,它们是以相同的方式设置的。问题是一个有效,另一个无效。我试着将一个复选框从破损的表单放到工作表单中,它开始工作,所以我认为在JavaScript Template.events代码中指定表单是一个问题 html: <template name="home"> <form> <strong>Display Factors:</strong><br> <label c

在我的home.html页面中,我有两个表单,它们是以相同的方式设置的。问题是一个有效,另一个无效。我试着将一个复选框从破损的表单放到工作表单中,它开始工作,所以我认为在JavaScript Template.events代码中指定表单是一个问题

html:

<template name="home">
<form> <strong>Display Factors:</strong><br> 
          <label class="display-F1"> <input type="checkbox" checked="{{displayF1}}"> 1: Cumplimiento de los objetivos del programa </label><br>
          <label class="display-F2"> <input type="checkbox" checked="{{displayF2}}"> 2: Estudiantes </label><br>
          <label class="display-F3"> <input type="checkbox" checked="{{displayF3}}"> 3: Profesores </label><br>
          </form>

          <form>
          <label class="display-strengths"> <input type="checkbox" checked="{{displayStrengths}}"> Display Strengths </label>
          <label class="display-insuff"> <input type="checkbox" checked="{{displayInsuff}}"> Display Insufficiencies </label>
          <label class="display-urgencies"> <input type="checkbox" checked="{{displayUrgencies}}"> Display Urgencies </label>
          </form>
</template>

我有其他依赖Session.get的代码,但我很有信心这段代码中存在问题,因为在控制台中,
Session.get('displayStrengths')
在适当的时候返回true,但是
Session.get('displayF1')
总是返回未定义的。

似乎问题不在于您提供的代码。查看我用您提供的代码制作的演示:


如果您运行它(打开chrome/firefox/任何控制台)并单击每个选项,您应该会看到正确的对应消息“我被称为X”。您还可以直接在控制台中键入
会话。键
,您应该会看到预期的结果。

我也在本地安装上测试了代码,似乎一切都很好。仍然不确定为什么它一开始不工作,但将一个窗体及其事件处理程序移动到单独的模板中是可行的。谢谢你的帮助
Template.home.events({
"change .display-strengths input": function (event) {
  Session.set("displayStrengths", event.target.checked);
},
"change .display-insuff input": function (event) {
  Session.set("displayInsuff", event.target.checked);
},
"change .display-urgencies input": function (event) {
  Session.set("displayUrgencies", event.target.checked);
},
"change .display-F1 input": function (event){
    Session.set("displayF1", event.target.checked);
},
"change .display-F2 input": function(event){
    Session.set("displayF2", event.target.checked);
},
"change .display-F3 input": function(event){
    Session.set("displayF3", event.target.checked);
},
});