1

向 JQM 列表视图添加动态选项在page1. 添加后,listview被刷新:

$('#list').listview('refresh');

选项链接到page2。在page2我有pagebeforeshow事件:

$('#page2').live('pagebeforeshow', function (e, data) {
    alert(data.prevPage.attr('id'));
});

data.prevPage.attr('id')is undefined when the option selected was the one added dynamically. 但对于另一种选择,完全没有问题。

page1为什么在列表视图中选择动态添加的选项时无法获取id?

4

1 回答 1

2

您的代码应该可以工作,看看这个例子:http: //jsfiddle.net/Gajotres/c2dU4/。我已经重新创建了您的案例,一切正常。

例子:

$('#index').live('pagebeforeshow',function(e,data){    
    $('#custom-list').append('<li><a href="#second">Link 4</a></li>');
    $('#custom-list').listview('refresh');
});

$("#second").live('pagebeforeshow', function (e,data) {
    alert(data.prevPage.attr('id'));
});

您是否可能试图通过 href 传递一些额外的数据?你能告诉我们更多你的代码吗?

于 2012-12-19T09:50:40.793 回答