2011-05-10 76 views

回答

4
$('.yourClass').click(function(e){ 
    //do something here 
}); 
+0

實施例:'

  • test
  • '然後使用 '$(文件)。就緒(函數(){ $()點擊(函數(e)中{ '頁'。 alert('Clicked'); }); });'不做任何事情,如果螢火蟲沒有任何錯誤,但沒有警報。 – Raoul 2011-05-10 14:57:45

    +0

    看看這個:http://jsfiddle.net/BdwTJ/。你提供的例子有效。也許這不是你的問題。您是否正確加載查詢? – user489872 2011-05-10 17:09:43

    +0

    jQuery加載正確,它被用於頁面上的其他東西沒有任何問題。我做了一個新的測試。該列表正在由jquery tmpl插件生成。如果我在同一頁面上手動創建具有相同屬性的列表,點擊功能可以正常工作。我想這是渲染不能與我的tmpl生成列表。 – Raoul 2011-05-11 09:35:24

    0
    $(".A").click(function() { 
        // do stuff for A 
    }); 
    
    $(".B").click(function() { 
        // do some other different stuff for B 
    }); 
    
    0
    jQuery('.A').click(function() { handler here }) 
    jQuery('.B').click(function() { another handler here }) 
    
    3

    你爲什麼不只需檢查函數內部的類?

    $("ol li a").click(function() { 
        if ($(this).hasClass("A")) { 
         // Do stuff if class = "A" 
        } else if ($(this).hasClass("B")) { 
         // Do stuff if class = "B" 
        } 
    }); 
    
    0
    $("LI.A").click(function() { 
        //your stuff 
    }); 
    
    相關問題