0

マルチページのJQMアプリに取り組んでいます。私のページの 1 つで、2 つの RSS フィードを取り込み、jFeed プラグインを使用して表示しています。

私がしたいのは、リストビューでクリック イベントをトラップし、href を取得して Phonegap/Cordova ChildBrowser プラグインに渡して、子ブラウザーに表示することです。

クリックされたイベントからhrefを取得するのに苦労しています。これがコンテキストまたは優先順位の問題なのか、それとも私が見逃している非常に単純なものなのかはわかりません。

含まれている app.js ファイルでは:

$("#chooseEvent").live('pageinit', function(event) {
  $.getFeed({
  url: "https://www1.ucsc.edu/news_events/calendar/rss/Today.ashx",
  complete: function(feed) {
  //called when complete
  //alert('complete');
  },
  success: function(feed) {
  //called when successful
  //alert('success' + feed.title);
  $("#content ul").append('<li data-role="divider" data-theme="b">' + feed.title + '</li>');
    for (var i = 0; i < feed.items.length && i < 10; i++) {
    var item = feed.items[i];
    $("#content ul").append('<li><a href="' + item.link + +"rel=external" + '">' + item.title + '</a></li>');
  }
  // run refresh on the listview to get the theme added correctly
  $('#content ul').listview('refresh');
  },
  error: function(feed) {
  //called when there is an error
  //alert('error');
  }
  // get the item clicked and prepare it for Child Browser
  $("#content ul").on('click', function(e) {
  //var url = this.href; // outputs #
  // var url = e.target; // outputs #
  var url = $(this).attr("href"); // result is undefined
  //var url = this.parent; // result in undefined
  alert(url);
  e.preventDefault();
 });
});

htmlページ

<div data-role="page" data-title="Campus Events" id="chooseEvent" addBackBtn="true">
<div data-role="header" data-add-back-btn="true">
<a href="index.html" rel="external" data-icon="arrow-l"  data-direction="reverse" class="ui-btn-left" data-theme="b">Back</a>
<h3>Today's Events</h3>
<a href="index.html" data-rel="back" data-icon="home" data-iconpos="notext"  data-direction="reverse" class="ui-btn-right" data-theme="b">Home</a>
</div>

<div data-role="content" id="content">
<ul data-role="listview" id="eventList" data-theme="b">

</ul>
</div> <!-- /content -->    
</div> <!-- /page -->
4

1 に答える 1

0

イベントでを取得するhrefには、新しく挿入されたタグにclickバインドしないでください。<li>

 $("#content li").on('click', function(e) {
     ...
     ...  
 });

というか、次のようなものです。

$('#content ul').delegate('li', 'click', function () {
    ...
    ...
});

どちらが優れているかはよくわかりません (実際には違いがあります)。

于 2012-05-18T17:47:26.657 に答える