【发布时间】:2016-11-18 11:50:13
【问题描述】:
如何通过点击按钮保存表单中的数据? 我不明白错误在哪里。 按计划,当您单击存储在变量“master”中的字段中的数据时
比如我用这个教程:http://www.w3schools.com/angular/angular_forms.asp
<!DOCTYPE html>
<html lang="en">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body> <div ng-app="myApp" ng-controller="formCtrl">
<form novalidate>
First Name:<br>
<input type="text" ng-model="firstName"><br>
<button ng-click="copyData()">Click Me!</button>
</form>
<p>form = {{user}}</p>
<p>master = {{master}}</p>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('formCtrl', function($scope) {
$scope.master = {uder.firstName};
$scope.reset = function() {
$scope.user = angular.copy($scope.master);
};
$scope.reset();
$scope.copyData=function(){
$scope.master1=angular.copy($scope.mas);
$scope.copyData();
}
});
</script>
</body>
</html>
【问题讨论】:
-
你到底想在这里做什么?
-
点击“点击我!”保存表单中的数据
-
您要保存哪些数据以及保存在哪里?
-
城市名称。字符串数据。
-
请浏览 w3schools 链接中提供的文档。您已将名字作为输入,并且您需要城市?
标签: javascript angularjs webforms