[英]Access HTML DOM from Javascript file (Meteor)
我不確定這是一個好問題還是正確的方法,但是我只是想知道如何使用Meteor禁用JS文件中的按鈕。
我嘗試過
$("#button").disabled = true;
而且它沒有用。 我不確定這是否是正確的方法。 我想到可能在HTML文件中的script標簽下創建一個函數,但是考慮到我有一個代表我的模型的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”更改為您的)
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.