<script>
$(document).on('change', '.botentry', function () {
if ($(this).val() == "") {
$(this).val(0);
}
});
</script>
我的html代码是
<tbody id=" tbody_Buid" ng-if="cstate!=''">
<tr ng-repeat="b in BottomsUpData | filter:{qtr: cqtr, state: cstate} | filter:searchData | orderBy:['-mtmsegment','bizgroup']" style="text-align:center">
<td><div>{{b.bizgroup}}</div></td>
<td><div>{{b.mtmsegment}}</div></td>
<td><div>{{b.family}}</div></td>
<td><div>{{b.series}}</div></td>
<td><div>{{b.formfactor}}</div></td>
<td><div><span ng-if="!b.freeze.m1 || !b.m1.isEdit">{{b.m1.value}}</span><input class="botentry" ng-if="b.freeze.m1 && b.m1.isEdit" ng-model="b.m1.value" ng-blur="buTotCalc()" type="number" /></div></td>
<td><div><span ng-if="!b.freeze.m2 || !b.m2.isEdit">{{b.m2.value}}</span><input class="botentry" ng-if="b.freeze.m2 && b.m2.isEdit" ng-model="b.m2.value" ng-blur="buTotCalc()" type="number" /></div></td>
<td><div><span ng-if="!b.freeze.m3 || !b.m3.isEdit">{{b.m3.value}}</span><input class="botentry" ng-if="b.freeze.m3 && b.m3.isEdit" ng-model="b.m3.value" ng-blur="buTotCalc()" type="number" /></div></td>
<td><div>{{b.m1.value+b.m2.value+b.m3.value}}</div></td>
</tr>
</tbody>
我添加此代码是为了避免在输入框中输入空字段,但它不适用于 AngularJs,Jquery 值零不与 angularjs ng-model 绑定(bind)。
最佳答案
在 Angular js 中,您使用 $scope
:
You don't update the input, you update the model to which the input is bound.
例如:
您的 html:
<div ng-controller="MyCtrl">
<input type='text' ng-model='input' ng-click="myFunction('some value')">
</div>
您的 Controller :
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.input = 1;
$scope.myFunction = function(value) {
$scope.input = value;
}
}
关于jquery - AngularJS 中的 Jquery $(this).val() 等价物是什么?如果更新后输入字段为空,如何将输入字段值设置为零?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51759910/