为什么我的Meteor应用程序无法识别我的功能?

时间:2015-08-10 20:58:57

标签: javascript meteor

我有一个<button>的流星应用。该按钮上有一个onclick事件,可调用函数verifypwd()。我的函数在名为verifypwd.js的文件中声明,该文件位于应用程序的主目录中。当我点击我的按钮时,它告诉我它无法找到该功能。怎么了?

这是我的代码:

HTML

<head>
  <title>KinnockPass</title>
  <script src="verifypwd.js"></script>
</head>

<body>
</body>

<template name="PPRO">
  <div class="vertibox">
    <div id="authorization-box">
      <div id="authorization">
         <h1>Are you a Riley?</h1>
         <input id="password" type="password"/>
         <button id="password-submit" onclick="verifypwd();">Yes, I Am.</button>
       </div>
     </div>
   </div>
 </template>

 <template name="passed">
 </template>

主要JS文件

//Define Route of PPRO Template
Router.route('/', {template: 'PPRO'});
Router.route('/passed');

pwd = new Mongo.Collection("pwd");

verifypwd.js

var verifypwd = function(){
  console.log("Hello");
}

1 个答案:

答案 0 :(得分:1)

Meteor包装所有函数,以便它们的范围仅限于它们所在的文件,除非它们被定义为全局函数。如果您从var移除var verifypwd,则应该有效。执行您尝试做的更为流行的方法是为您的PPRO模板定义template event并将 verifypwd 代码放在同一个文件中,然后它可以是本地功能。

相关问题