ionic数字键盘
程序员文章站
2022-03-18 12:53:28
...
ionic最近挺火,最近我也在玩这个,本例实现在用户点击输入框时弹出数字键盘。
效果如下
关键代码
<script id="templates/modal_number_keyboard.html" type="text/ng-template"> <ion-modal-view > <ion-header-bar class="bar bar-header bar-positive"> <h1 class="title" ng-bind="currentNumber" ></h1> </ion-header-bar> <ion-content class="padding"> <div class="col col-offset-10"> <button class="button button-outline button-positive" ng-click="doInput(num.f);" >6</button> <button class="button button-outline button-positive" ng-click="doInput(num.g);" >7</button> <button class="button button-outline button-positive" ng-click="doInput(num.h);" >8</button> <button class="button button-outline button-positive" ng-click="doInput(num.i);" >9</button> </div> <div class="col col-offset-10"> <button class="button button-outline button-positive" ng-click="doInput(num.b);" >2</button> <button class="button button-outline button-positive" ng-click="doInput(num.c);" >3</button> <button class="button button-outline button-positive" ng-click="doInput(num.d);" >4</button> <button class="button button-outline button-positive" ng-click="doInput(num.e);" >5</button> </div> <div class="col col-offset-10"> <button class="button button-outline button-positive" ng-click="doInput(num.a);" >1</button> <button class="button button-outline button-positive" ng-click="doInput(num.j);" >0</button> <button class="button button-outline button-positive" ng-click="doInput(num.k);" >.</button> <button class="button button-outline button-positive" ng-click="doInput(num.l);" >C</button> </div> <div class="col col-offset-10"> <button class="button button-outline button-positive" ng-click="modalNumberKeyboard.hide()" >取消</button> <button class="button button-outline button-positive" ng-click="finishInput()">确定</button> </div> </ion-content> </ion-modal-view> </script>
$ionicModal.fromTemplateUrl('templates/modal_number_keyboard.html', { scope: $scope }).then(function(modal) { $scope.modalNumberKeyboard = modal; }); $scope.currentNumber=""; $scope.num={"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7,"h":8,"i":9,"j":0,"k":".","l":"C"}; $scope.doInput=function(n){ if(n=="C"){//清除键 $scope.currentNumber=""; }else if(n=="."){// .键 if( $scope.currentNumber!=""&&$scope.currentNumber.indexOf(".")==-1){ $scope.currentNumber=$scope.currentNumber+""+n; } }else if(n==0){//0键 if($scope.currentNumber==""||$scope.currentNumber!=0||$scope.currentNumber.indexOf(".")!=-1){ $scope.currentNumber=$scope.currentNumber+""+n; } }else if(n!=0&&n!="."&&n!="C"){//1-9键 if($scope.currentNumber=="0"){ $scope.currentNumber=n; }else{ $scope.currentNumber=$scope.currentNumber+""+n; } } }; var currentInput; $scope.showKeyBoard=function(t){ $scope.modalNumberKeyboard.show(); currentInput=t; }; $scope.finishInput=function(){ eval('$scope.'+currentInput+'=$scope.currentNumber==""?"0":$scope.currentNumber;'); $scope.modalNumberKeyboard.hide(); }
代码在附件中
如果您觉得我的文章给了您帮助,请为我买一杯饮料吧!以下是我的支付宝,意思一下我将非常感激!
推荐阅读
-
IOS数字键盘左下角添加完成按钮的实现方法
-
iOS开发之UIKeyboardTypeNumberPad数字键盘自定义按键
-
Android开发之如何自定义数字键盘详解
-
iOS开发之UIKeyboardTypeNumberPad数字键盘自定义按键
-
blender怎么开启模拟数字键盘? blender笔记本数字键盘的使用方法
-
ionic App 解决android端在真机上tab处于顶部的问题
-
blender怎么开启模拟数字键盘? blender笔记本数字键盘的使用方法
-
VS2017 Cordova Ionic2 移动开发环境搭建教程
-
Android自定义密码输入框和数字键盘
-
简单实现IONIC购物车功能