小编典典

如何控制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.

有什么建议么??


阅读 278

收藏
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