首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么这个在气象卫星上的提交功能不能工作?

为什么这个在气象卫星上的提交功能不能工作?
EN

Stack Overflow用户
提问于 2015-03-18 21:24:42
回答 1查看 43关注 0票数 0

我有一个由7个问题组成的表格。我个别地要求他们使用显示:无。但问题是提交函数不起作用。当我点击它时,它只是重定向回第一个问题,然后url转到- http://localhost:3000/?problem=&why1=&why2=&why3=&why4=&why5=&solution=&submit-all=Answer。这件事我真的需要帮助。下面是HTML和JavaScript提交函数在问题集合中提交的代码。

代码语言:javascript
复制
<template name="submitProblem">
  <div class="container">
    <div class="main-page">
      <form class="text-center">
        <div id="submit-problem">
          <input autofocus="autofocus" type="text" name="problem" id="problem" placeholder="What's the problem ?"/>
          <input type="button" id="route" value="Find Its Route" class="route btn btn-sample">
        </div>

         ...
        submit-why1 - submit-why4
         ...

        <div id="submit-why5" class="hidden">
          <input autofocus="autofocus" type="text" id="why5" class="" name="why5" placeholder="This problem exists, because..."/>
          <input type="button" value="Answer" class="btn-success btn answer5">
          <button class="btn back5 back-btn"><i class="fa fa-arrow-left fa-3x"></i></button>
        </div>

        <div id="submit-solution" class="hidden">
          <input autofocus="autofocus" type="text" name="solution" id="solution" placeholder="What could be the best solution ?"/>
            
          <input type="submit" id="submit-all" name="submit-all" value="Answer" class="btn btn-primary submit-all">

          <button class="btn back6 back-btn"><i class="fa fa-arrow-left fa-3x"></i></button>
        </div>
      </form>
    </div>
  </div>
</template>

代码语言:javascript
复制
Template.submitProblem.events({
  'submit .submit-all':function() {
    event.preventDefault();
    var problem = $(event.target).find('[name=problem]').val();
    var why1 = $(event.target).find('[name=why1]').val();
    var why2 = $(event.target).find('[name=why2]').val();
    var why3 = $(event.target).find('[name=why3]').val();
    var why4 = $(event.target).find('[name=why4]').val();
    var why5 = $(event.target).find('[name=why5]').val();
    var solution = $(event.target).find('[name=solution]').val();

   Problems.insert({
      problem: problem,
      why1: why1,
      why2: why2,
      why3: why3,
      why4: why4,
      why5: why5,
      solution: solution,
      submitdate: new Date()
    });

    console.log(problem + why1 + why2 + why3 + why4 + why5 + solution);

    Router.go('submitted');
  }
});

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-18 21:28:11

您需要将event作为第一个参数传递给处理程序:

代码语言:javascript
复制
submit: function(event) {
  event.preventDefault();
  ...

否则它将不会被定义,默认操作( POST)不会被阻止,您的页面将重新加载。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29132989

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档