2014-11-14 36 views
1

我正在創建一個jQuery手機網站。我想使用jquery移動過濾器來獲取孩子的詳細信息。現在,我可以在輸入孩子名稱時觸發數據。那麼我將點擊「搜索」按鈕。它將顯示數據庫中的匹配名稱。但是當我點擊這個名字(比如「Reegan」或者「Reegan1」)時,它並沒有從數據庫中填充其餘的值。點擊jquery移動過濾器數據時如何獲取詳細信息?

然後我想去其他頁面並打印孩子的詳細信息。我使用json Url從數據庫中提取值。請幫助我解決問題。

這是我的代碼:

$("#btnSearch").click(function() { 
    var child_name = $("#search-1").val(); 
    helper.actionGet("http://.../SearchChildJSON", { 
      name: child_name 
     }, 
     function (data) { 
      console.log(data); 
      var rec_data = jQuery.parseJSON(data); 
      sessionStorage.setItem("AllData",data); 
      $.each(rec_data, function (index, value) { 
       $("#push_name").append("<a id='"+value.CMOId+"' href='#' class='ui-btn ui-shadow ui-corner-all'>" + value.FirstName + "</a>"); 
      }); 
     }); 
    $("#push_name").on("click","a",function(val) { 
     console.log(val); 
    }); 
}); 

我試圖讓濾波器數據,如 「Reegan」。我的控制檯答覆

m.Event {originalEvent: MouseEvent, type: "click", isDefaultPrevented: function, timeStamp: 1416223135795, jQuery111109369461725000292: true…} 

圖像的數據:

enter image description here

JQuery手機html文件:

<div data-role="content"> 
     <label for="search-1">Child:</label> 
     <form> 
      <input data-type="search" class="filterControlgroup-input" id="search-1"  placeholder="Search Child..."> 
     </form> 
      <div data-role="controlgroup" data-filter="true" data-input=".filterControlgroup-input" data-filter-reveal="true" id="push_name"> 
     </div> 
</div> 
<div data-role="footer" data-position="fixed"> 
     <button class="ui-btn ui-corner-all ui-btn-inline" class="btnSearch" id="btnSearch">Search</button> 
</div> 

回答

1

委託click事件動態添加錨點(按鈕)。

$(document).on("pagecreate", "#pageID", function() { 
    $("#push_name").on("click", "a", function() { 
    var btnID = this.id, /* or $(this)[0].id */ 
     btnText = this.innerText; /* or $(this).text() */ 
    }); 
}); 
+0

感謝bro.I得到 「m.Event {originalEvent:的MouseEvent,鍵入: 」點擊「,isDefaultPrevented:功能,時間戳:1416202087374,jQuery111109532860720064491:真...}」 當我給一個參數與功能。但我能夠得到'reegan'的細節。 – reegan29 2014-11-17 05:30:24

+1

@ reegan29可以使用導致該錯誤的代碼更新您的帖子嗎? – Omar 2014-11-17 08:49:55

+0

請參閱我的更新.. – reegan29 2014-11-17 11:27:33

相關問題