標籤:www 使用者名稱 submit css model 提交 on() location blog
本文和大家分享的主要是前端開發中必備的AngularJs架構表單開發相關基礎知識,希望對大家使用和學習AngularJs有所協助。
1.簡單的表單提交;
2.更多的表單元素;
3.初始化表單;
代碼
<!doctype html>
<html ng-app="lesson" ng-controller="FormCtrl" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>
LESSON 7
</title>
<link rel="stylesheet" type="text/css" href="css/main.css" />
<style>
#content1{padding:16px;}
</style>
</head>
<body>
<form ng-submit="PostForm()" >
<ul>
<li>
<label>使用者名稱:</label><input type="text" ng-model="form.UserName" />
</li>
<li>
<label>暱稱:</label><input type="text" ng-model="form.NickName" />
</li>
<li>
<label>年齡:</label><input type="text" ng-model="form.Age" />
</li>
<li>
<label>是否已婚:</label><input type="checkbox" ng-model="form.IsMarried" />
</li>
<li>
<label>喜愛的動物:</label>
<input type="radio" ng-model="form.LovedAnimal" value="狗" />狗
<input type="radio" ng-model="form.LovedAnimal" value="貓" />貓
</li>
<li>
<label>居住的城市:</label>
<select ng-model="form.LocationCity"
ng-options=" obj.text as obj.value for obj in form.LocationCityList"
>
<option value="">請選擇城市</option>
</select>
</li>
<li>
<input type="submit" value="提交" />
</li>
</ul>
</form>
<ul>
<li>{{form.UserName}}</li>
<li>{{form.NickName}}</li>
<li>{{form.Age}}</li>
<li>{{form.IsMarried}}</li>
<li>{{form.LovedAnimal}}</li>
<li>{{form.LocationCity}}</li>
</ul>
<script src="scripts/angular-1.4.6.min.js"></script>
<script>
var app = angular.module("lesson",[]);
app.controller("FormCtrl",function($scope){
$scope.formInitObj = {
UserName:"",
NickName:"",
};
$scope.form = {};
$scope.form.LocationCityList = [
{text:"北京",value:"北京"},
{text:"上海",value:"上海"},
{text:"廣州",value:"廣州"}
];
$scope.PostForm=function(){
console.log($scope.form);
$scope.form = angular.copy($scope.formInitObj);
}
});
</script>
</body>
</html>
執行結果
原文連結:http://www.maiziedu.com/wiki/angularjs/develop/
AngularJs入門之表單開發