input标签中有一个id,我怎么总angularjs取得这个id的值呢
<body onload='test()'>
<div ng-app="myApp" ng-controller="formCtrl">
<input type="text" id='aaaa' ng-model="user.firstName"><br>
<button ng-click="showvalue()">获取</button>
</div>
<script>
function test(){
alert(document.getElementById('aaaa').value);
}
var app = angular.module('myApp', []);
app.controller('formCtrl', function($scope) {
$scope.master = {firstName:"John1", lastName:"Doe"};
$scope.showvalue = function() {
alert($scope.user.firstName);
};
$scope.user = angular.copy($scope.master);
});
</script>
不知道你说的是获取input的值还是input那个jqlite对象。。。。
如果是值,这本来就是angular双向绑定解决的
如果是jqlite对象,用angular.element("#test");test是input的id。angular.element返回值就是一个jqlite对象