AngularJS angular.uppercase()函数用法示例

2021年4月9日16:43:24 发表评论 959 次浏览

AngularJS中的angular.uppercase()函数用于将字符串转换为大写。当用户想要用大写字母而不是小写字母显示文本时,可以使用它。

语法如下:

angular.uppercase(string)

例子:在此示例中, 字符串被转换为大写。

<html ng-app = "app">
<head>
<script src =
"https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js">
</script>
     <title>angular.uppercase()</title>
     </head>
     <body style = "text-align:center">
      <h1 style = "color:green">lsbin</h1>
      <h2>angular.uppercase()</h2>
      <div ng-controller = "geek">
      <br>
      <b>Before: </b>{{ string1 }}
      <br><br>
      <button id = "myButton" ng-mousedown = "upper()">Click it!
      </button>
      <br><br>
  
      <b>After: </b>{{ string2 }}
      </div>
  
      <script>
        var app = angular.module('app', []);
        app.controller('geek', function($scope) {
        $scope.obj1 = 
        "lsbin is the computer science portal for geeks."
        $scope.obj2;
        $scope.string1 = $scope.obj1;
        $scope.upper = function() {
        $scope.string2 = angular.uppercase($scope.obj1);
        }
     });
     </script>
     </body>
</html>

输出如下:

点击前:

uppercase()函数

点击后:

uppercase()函数

木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: