简体   繁体   English

从Javascript文件(流星)访问HTML DOM

[英]Access HTML DOM from Javascript file (Meteor)

I'm not sure if this is a good question or even a right approach but I'm just wondering how I could possibly disable a button from my JS file using Meteor. 我不确定这是一个好问题还是正确的方法,但是我只是想知道如何使用Meteor禁用JS文件中的按钮。

I attempted 我尝试过

$("#button").disabled = true;

And it didn't work. 而且它没有用。 I'm not sure if this is the right approach or not. 我不确定这是否是正确的方法。 I thought of maybe creating a function under a script tag in my HTML file but I thought that would seem redundant considering I have a JS file which represents my model so I was just attempting on figuring out if I can access HTML tags from that file. 我想到可能在HTML文件中的script标签下创建一个函数,但是考虑到我有一个代表我的模型的JS文件,我认为这似乎是多余的,所以我只是想弄清楚是否可以从该文件访问HTML标签。

Here's the code: 这是代码:

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:''
    };

  }

 }]);
}

First, I'm not angularjs user. 首先,我不是angularjs用户。 But your code must to run template render after. 但是您的代码必须在之后运行模板渲染。 try to change your code like below. 尝试如下更改您的代码。 (Note: "yourTemplate" change to yours) (注意:“ yourTemplate”更改为您的)

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: ''
          };

        }

      }
    ]);
  });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM