脚本无法正常工作

时间:2016-11-24 08:07:43

标签: javascript html angularjs

<!DOCTYPE html>
<html >
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body ng-app="notePad" ng-controller="notePadCtrl">

<textarea ng-model="message"></textarea>
<button ng-click="save()">save</button>
<button ng-click="clear()">clear</button>

<script src="notePad.js"></script>
<script src="notePadCtrl.js"></script>

</body>
</html>
var app = angular.module("notePad", [] );

app.controller("notePadCtrl",function($scope){
    $scope.message="";
    $scope.left=function(){
        return 100 - $scope.message.lenght;
    };
    $scope.clear=function(){
        $scope.message="";
    };
    $scope.save=function(){
        alert("file got saved");
    };
)};

2 个答案:

答案 0 :(得分:2)

这是一个错误!替换最后一行。

)};替换为});

答案 1 :(得分:-2)

此代码中存在几个问题。首先应该改变控制器支架的关闭

app.controller("notePadCtrl",function($scope){
    $scope.message="";
    $scope.left=function(){
        return 100 - $scope.message.lenght;
    };
    $scope.clear=function(){
        $scope.message="";
    };
    $scope.save=function(){
        alert("file got saved");
    };
});

然后在body或head标签内添加angular script标签

<!DOCTYPE html>
<html>

  <head>
    <script data-require="angular.js@1.5.8" data-semver="1.5.8" src="https://code.angularjs.org/1.5.8/angular.js"></script>
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
  </head>

  <body ng-app="notePad" ng-controller="notePadCtrl">
    <textarea ng-model="message"></textarea>
    <button ng-click="save()">save</button>
    <button ng-click="clear()">clear</button>
  </body>

</html>

查看pluker