如标题所述,如何使用angularjs在div内获取文本?IE:
<div class='container' ng-app=''>
<input type='text' ng-model='qty'>
<div class='price'></div>
<div class='total'>{{qty * price}}</div>
</div>
输入是可编辑的,并且可以用任何数字填充,而价格是固定的,不可编辑,但是对于每个项目来说都是不同的,现在我如何使用AngularJS获取价格的内容并将其乘以输入的数量并显示总计div中的总计?
您需要initialize
在控制器中设置值。
function MyCtrl($scope) {
$scope.price= $('.price').text();
$scope.qty=0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app>
<div ng-controller="MyCtrl">
<input type="text" ng-model='qty'>
<div class="price">3.4</div>
<div class='total'>Total: {{ qty * price }}</div>
</div>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句