0

我正在尝试将 jQuery 程序从 1.8 版升级到 1.9 版。在早期版本中 .live() 方法工作正常,但新的 .on() 方法不能。发送到检索数据的 Web 服务的参数“KenID”是“未定义的”,因此不返回任何数据。此参数设置为 sessionStorage 项,所以我猜 .on() 方法无权访问它。我应该采取哪些步骤才能使其发挥作用?

工作程序(jQuery 1.8):

$('#AddrList').live('pagebeforeshow', function (e, data)
    {
        alert(sessionStorage.KenID);    // shows correct KenID
        $.ajax({ 
            // extracting required data by sending KenID to the web service
        });
});

不工作的程序(jQuery 1.9):

$(document).on('pagebeforeshow', '#AddrList', function (e, data)
    {
        alert(sessionStorage.KenID);    // shows "undefined"
        $.ajax({
            // extracting required data by sending KenID to the web service
        });
});

谢谢你,雅克

4

1 回答 1

0

我有两个简单的问题要问。

  1. 你确定#AddrList是你页面的id吗?
  2. 您确定在导航到当前页面之前已经设置了值sessionStorage.KenID吗?

如果您对我上面提出的两个问题的回答都是肯定的,那么它应该可以正常工作。

这里有一个Live example

于 2013-04-08T04:52:37.940 回答