从获得的输入值(AngularJS) [英] Get value from input (AngularJS)

查看:167
本文介绍了从获得的输入值(AngularJS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的输入,需要他们的值:

I have the following inputs and need their values:

<input type="hidden" ng-model="movie" value="harry_potter"/>
<input type="text" ng-model="year" value="2000"/>

我能做些什么来让每个输入端的价值?

What can I do to get the value of each input?

推荐答案

试试这个

这是例如,从 文件AngularJS

This is example from Doc AngularJS

<html ng-app>
  <head>
    <script src="http://code.angularjs.org/1.2.7/angular.min.js"></script>
  </head>
  <body>
    <div ng-controller="Controller">
      <form novalidate class="simple-form">
        Name: <input type="text" ng-model="user.name" /><br />
        E-mail: <input type="email" ng-model="user.email" /><br />
        Gender: <input type="radio" ng-model="user.gender" value="male" />male
        <input type="radio" ng-model="user.gender" value="female" />female<br />
        <button ng-click="reset()">RESET</button>
        <button ng-click="update(user)">SAVE</button>
      </form>
      <pre>form = {{user | json}}</pre>
      <pre>master = {{master | json}}</pre>
    </div>
    <script>
      angular.module('formExample', [])
      .controller('ExampleController', ['$scope', function($scope) {
        $scope.master = {};

        $scope.update = function(user) {
          $scope.master = angular.copy(user);
        };

        $scope.reset = function() {
          $scope.user = angular.copy($scope.master);
        };

        $scope.reset();
      }]);
    </script>
  </body>
</html>

这篇关于从获得的输入值(AngularJS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆