一尘不染

如何控制jQuery Mobile中的后退按钮事件?

javascript

我试图控制后退按钮,但我不能。

  event.keyCode == 27 //thats for escape 
  event.keyCode == 8 //thats for backspace..its also working on browser but it doesnt work on my tablet.

有什么建议么??


阅读 266

收藏
2020-05-01

共1个答案

一尘不染


您需要听navigation事件和state.direction

$(window).on("navigate", function (event, data) {
  var direction = data.state.direction;
  if (direction == 'back') {
    // do something
  }
  if (direction == 'forward') {
    // do something else
  }
});

jQM API: 导航事件

2020-05-01