根据在线示例,我在 login.html
中有类似的内容:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js"></script>
<script type="text/javascript" src="app/app.login.js"></script>
<div id="loginButton" ng-app="loginButton" ng-controller="loginControl">
<button ng-click="enterSite()">
Enter
</button>
</div>
然后在app.login.js
中:
var appButton = angular.module("loginButton", []);
appButton.controller("loginControl", ["$scope", "$window", function($scope, $window){
$scope.enterSite = function(){
$window.location.href = "../index.html";
}
}]);
但是,当我按下按钮时,它不会重定向到 index.html
。浏览器日志中没有错误。我已经从工作示例中复制了大部分格式,因此我无法找到为什么它对我不起作用。
如有任何提示,我们将不胜感激。
最佳答案
您的代码可以按原样运行,无需任何更改。
如果您发现任何与 JavaScript 相关的问题或脚本未从 ajax.googleapis.com 加载,请检查您的本地系统。
检查您是否已正确链接您的login.js
var appButton = angular.module("loginButton", []);
appButton.controller("loginControl", ["$scope", "$window", function($scope, $window){
$scope.enterSite = function(){
$window.location.href = "../index.html";
}
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js"></script>
<script type="text/javascript" src="app/app.login.js"></script>
<div id="loginButton" ng-app="loginButton" ng-controller="loginControl">
<button ng-click="enterSite()">
Enter
</button>
</div>
关于javascript - 单击按钮更改页面(AngularJS)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37765851/