2014-09-21 49 views

回答

3

請查看更多https://docs.angularjs.org/guide/databinding

enter image description here

var app= angular.module("app",[]).controller('fCtrl', function($scope){ 
 

 
$scope.elementName = "testName"; 
 
$scope.myElement = { 
 
    value:"some value", 
 
    name:"myInput" 
 
} 
 
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app="app"> 
 
<div ng-controller="fCtrl"> 
 
    
 
    <input type="text" ng-model="myElement.value" name="{{myElement.name}}"> 
 
    <hr/> 
 
    name only 
 
    <br/> 
 
    
 
    <input type="text" name="{{elementName}}"> 
 
    </div> 
 
    
 
</div>

+0

謝謝。但是我需要input元素中的name屬性,這是我問的問題。 – user1342336 2014-09-21 22:17:28

+0

@ user1342336你想要設置名稱屬性嗎? – sylwester 2014-09-21 22:19:09

+0

@ user1342336請參閱更新的answear – sylwester 2014-09-21 22:35:46

相關問題