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