Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/399.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/8/meteor/3.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)访问HTML DOM_Javascript_Meteor - Fatal编程技术网

从Javascript文件(Meteor)访问HTML DOM

从Javascript文件(Meteor)访问HTML DOM,javascript,meteor,Javascript,Meteor,我不确定这是一个好问题还是一个正确的方法,但我只是想知道如何使用Meteor从我的JS文件中禁用一个按钮 我试图 $("#button").disabled = true; 但它不起作用。我不确定这是否是正确的方法。我想在我的HTML文件中的脚本标记下创建一个函数,但考虑到我有一个代表我的模型的JS文件,我认为这似乎是多余的,所以我只是想弄清楚是否可以从该文件访问HTML标记 代码如下: Users = new Mongo.Collection("user-info"); if (Meteor

我不确定这是一个好问题还是一个正确的方法,但我只是想知道如何使用Meteor从我的JS文件中禁用一个按钮

我试图

$("#button").disabled = true;
但它不起作用。我不确定这是否是正确的方法。我想在我的HTML文件中的脚本标记下创建一个函数,但考虑到我有一个代表我的模型的JS文件,我认为这似乎是多余的,所以我只是想弄清楚是否可以从该文件访问HTML标记

代码如下:

Users = new Mongo.Collection("user-info");
if (Meteor.isClient) {
  var myApp = angular.module('calorie-counter',['angular-meteor']);

  myApp.controller('formCtrl',['$scope',function($scope) {
  $("#button").disabled=true;

  $scope.calories;
  $scope.goal;
  $scope.user;

  $scope.submit = function() {
    Meteor.call("submit",$scope.user);
    $scope.clear();
  }

  $scope.clear = function() {
    $scope.user = {
      item1:'',
      item2:'',
      calories:'',
      goal:''
    };

  }

 }]);
}

首先,我不是angularjs用户。 但您的代码必须在之后运行模板渲染。 尝试如下更改代码。(注意:“yourTemplate”更改为您的)


首先,我不是angularjs用户。 但您的代码必须在之后运行模板渲染。 尝试如下更改代码。(注意:“yourTemplate”更改为您的)


你能给我看看你的JS代码吗?我需要知道代码的正确点。我认为您的问题是在模板呈现之前调用jQuery函数。我希望这会有帮助。你能给我看一下你的整个JS代码吗?我需要知道代码的正确点。我认为您的问题是在模板呈现之前调用jQuery函数。我希望这会有帮助。
Users = new Mongo.Collection("user-info");

if (Meteor.isClient) {

  Template.yourTemplate.onRendered(function() {

    var myApp = angular.module('calorie-counter', ['angular-meteor']);

    myApp.controller('formCtrl', ['$scope',
      function($scope) {
        $("#button").disabled = true;

        $scope.calories;
        $scope.goal;
        $scope.user;

        $scope.submit = function() {
          Meteor.call("submit", $scope.user);
          $scope.clear();
        }

        $scope.clear = function() {
          $scope.user = {
            item1: '',
            item2: '',
            calories: '',
            goal: ''
          };

        }

      }
    ]);
  });
}