请问微信小程序(wxml或者html)中怎么实现下面的功能
发布网友
发布时间:2022-04-23 03:11
我来回答
共2个回答
热心网友
时间:2022-05-18 21:59
使用的angular.js来实现,具体代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.bootcss.com/angular.js/1.4.6/angular.min.js"></script>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<input type="text" ng-model="aNum" ng-keyup="getResult()">+
<input type="text" ng-model="bNum" ng-keyup="getResult()">-
<input type="text" ng-model="cNum" ng-keyup="getResult()">=
<div id="result" style="display:inline" ng-model="result">{{result||'null'}}</div>
</div>
<script>
var app = angular.mole('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.aNum = "";
$scope.bNum = "";
$scope.cNum = "";
$scope.result = $scope.aNum + $scope.bNum+$scope.cNum;
$scope.getResult = function(){
var newResult = Number($scope.aNum)+Number($scope.bNum)-Number($scope.cNum);
$("#result").text(newResult);
}
});
</script>
</body>
</html>