0
我試圖在我按下後退按鈕時獲得前一個狀態。在檢查中,我可以看到popstate功能也被稱爲前進按鈕。儘管popstate函數被執行,但它並沒有返回到之前的狀態事件。我無法理解如何正確地協調事件,因爲我是前端開發的新手。 在此先感謝!history.popstate不能正常工作,並且在瀏覽器中被稱爲前後按鈕
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
<script src="aid.js"> </script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<div id="one" ng-hide="val_1">{{val_1}} ONE </div>
<div id="two" ng-show="val_2">{{val_2}} TWO </div>
<button id="but" ng-click=myfun()> pressme </button>
</body>
</html>
aid.js
//the js code
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.val_2 = false;
$scope.val_1 = false;
$scope.myfun = function() {
$scope.val_1 = true;
$scope.val_2 = true;
history.pushState("","","new");
}
window.addEventListener('popstate',function()
{
$scope.val_2 = false;
$scope.val_1 = false;
});
});