簡體   English   中英

JQuery 移動設備:列表視圖項目上的點擊事件也會觸發隱藏的 object 事件

[英]JQuery mobile: Tap event on listview item also fires hidden object event

我在動態生成的列表視圖上的點擊事件有問題。 當我 select 列表中的第一項時,動作是火災,其中一個是取消隱藏附近的 object。 問題是未隱藏對象的點擊事件也在那個時候觸發。 我沒有廣泛的編程背景,但我從事軟件測試,因此您可以期待徹底的復制步驟。 :)

這是選擇任何列表項時觸發的事件:

//When a list item is selected
    $('#showItems').delegate('li', 'tap', function () {
        if ($('#showItems').hasClass("courses")){
            courseNum = $(this).find('.course').text();
            var profArr=new Array();
            profArr[0]="";
            profArr[1]="";
            ajax_get_textbooks(courseNum, profArr[1], profArr[0]);
            $('#showItems').removeClass('profs courses booksProf eitems').addClass('books');
        }
        else if ($('#showItems').hasClass("profs")){
            prof = $(this).text();
            profArr = prof.split(", ");
            ajax_get_textbooks(courseNum, profArr[1], profArr[0]);
            $('#showItems').removeClass('profs courses books eitems').addClass('booksProf');
        }
        $('#filters').removeClass('hidden'); // this is the object that gets acted upon incorrectly
    });

這是在選擇第一個列表元素時也會觸發的事件:

//When filter by professor/e-resources is selected
 $('.filterBtn').bind('tap',function(event){
    var filter = $(this).text();
    filter = filter.toLowerCase();
    if (filter.indexOf("prof") !== -1 ) {
        ajax_filter_professor(courseNum);
        $('#showItems').removeClass('books courses booksProf eitems').addClass('profs');
    }
    else {
        ajax_filter_eresources(courseNum);  
        $('#showItems').removeClass('books profs booksProf courses').addClass('eitems');
    }
    $('#showItems').listview('refresh');
});

我想我可以通過將 taphold 事件附加到同一個 function 來解決這個問題,但是以下行不起作用:

$('#showItems').delegate('li', 'tap taphold', function () {

僅當我將相同的代碼復制到新的事件觸發器中以進行點擊時,它才有效。

我希望能夠以某種方式禁用 $('.filterBtn').bind 直到第一個列表完成刷新,但無法弄清楚如何做到這一點。

以下是復制步驟

  1. http://library.iit.edu/mbad/#textbooks在文本框中輸入“hu”。 課程列表傳播。
  2. 選擇第一個列表項 (HUM102)。
  3. 請注意,您的鼠標現在懸停在兩個按鈕之一上:“by Prof”或“E-items”。 如果您在手機上對此進行測試,其中一個按鈕事件也會觸發。

有人可以幫我弄清楚我做錯了什么嗎?

也許您可以嘗試使用 JQM 的 vclick 事件。 請參閱http://jquerymobile.com/test/docs/api/events.html上的 JQM 中支持的事件列表 如果不是 Vclick,其他可能適合。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM