Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.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/1/angularjs/24.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 如何将参数从html传递到js?_Javascript_Angularjs - Fatal编程技术网

Javascript 如何将参数从html传递到js?

Javascript 如何将参数从html传递到js?,javascript,angularjs,Javascript,Angularjs,我试图通过以下方式传递输入值: html 但是,这样做我什么也抓不到。我也尝试过使用fiche.submitEdit({{q}}),但它不起作用。有什么好主意吗 非常感谢 当您使用ng模型时,无需传递数据,请尝试 <table ng-app="m"> <tr ng-controller="fCtrl"> <td> <span> <input type="checkbox" name="q" ng-model="qo"

我试图通过以下方式传递输入值:

html

但是,这样做我什么也抓不到。我也尝试过使用
fiche.submitEdit({{q}})
,但它不起作用。有什么好主意吗


非常感谢

当您使用ng模型时,无需传递数据,请尝试

<table ng-app="m">
<tr ng-controller="fCtrl">
<td>
    <span>
        <input type="checkbox" name="q" ng-model="qo" >
        <input type="checkbox" name="q" ng-model="qa" >
    </span>
</td>
<td>
    <button type="submit" class="btn btn-primary" ng-click="submitEdit()">Modifier</button>
</td>
</tr>
</table>
(function(){
var app = angular.module('m', [ ]);

app.controller('fCtrl', function($scope){
    $scope.qo = "";
    $scope.submitEdit = function(){
         alert($scope.qo);
    }
});

})();

修饰语
(功能(){
var app=angular.module('m',[]);
应用控制器('fCtrl',功能($scope){
$scope.qo=“”;
$scope.submitEdit=函数(){
警报($scope.qo);
}
});
})();

我从未使用过控制器别名。 这应该行吗

(function(){
var app = angular.module('m', [ ]);

app.controller('fCtrl', ['$scope',function($scope){
    $scope.submitEdit = function(){
         alert($scope.qo);
    }
}]);

})();

在html中,只需调用ng click=“submitdit()”

首先,在
ng模型中始终使用点。这几乎就是你想要做的,当你提交时,你会有一个对象
q

ng模型
的强大部分是,如果范围对象不存在,它将创建范围对象

在您的情况下,如果您将
ng模型
更改为
q.a
q.o
,您的方法将起作用,并且您将有一个对象
q
在属性
a
o
的范围内

但是,您还设置了一个控制器别名,因此现在需要使用该控制器别名作为所有html范围变量的前缀

<input type="checkbox" name="q" ng-model="fiche.q.o" >
<input type="checkbox" name="q" ng-model="fiche.q.a" >

<button ng-click="fiche.submitEdit(fiche.q)">


 $scope.submitEdit = function(q){
     alert($scope.q.o);
}

$scope.submitEdit=函数(q){
警报($scope.q.o);
}

实际上不需要将对象作为参数传递,因为它在作用域中已作为
$scope.q

存在。为此,我收到了以下错误消息
ReferenceError:$scope未在提交时定义(http://localhost/dashboard/public/js/app.js:16:25)在http://localhost/dashboard/vendor/angular/angular.min.js:175:290     在http://localhost/dashboard/vendor/angular/angular.min.js:192:357     以k$eval的价格(http://localhost/dashboard/vendor/angular/angular.min.js:111:353)以千元申请(http://localhost/dashboard/vendor/angular/angular.min.js:112:121)在HTMLButtoneElement。(http://localhost/dashboard/ve
您是否编写了ng app=“m”如果你使用的是正确的angular js库,我的代码应该可以运行,详细信息你可以检查嘿,你有没有检查过它是否在像我一样添加ng应用程序后运行,检查y代码。你希望
q
是什么?你的标记或范围中没有任何东西与之匹配输入上的
名称
。因此,当您将其作为函数的参数传递时,它是未定义的
(function(){
var app = angular.module('m', [ ]);

app.controller('fCtrl', ['$scope',function($scope){
    $scope.submitEdit = function(){
         alert($scope.qo);
    }
}]);

})();
<input type="checkbox" name="q" ng-model="fiche.q.o" >
<input type="checkbox" name="q" ng-model="fiche.q.a" >

<button ng-click="fiche.submitEdit(fiche.q)">


 $scope.submitEdit = function(q){
     alert($scope.q.o);
}