js多個


$('ul').on("click","li#left",function(){
            currentProvince = $(this).text().replace(/[0-9]/ig,"");
            $(this).siblings().removeClass('choose');
            $(this).addClass('choose');
            refreshTypeByProvince(currentProvince);
            refreshOrderCountByProvinceAndOrderType(currentProvince,currentOrderType);
            refreshUserOrderInfoByProvinceAndOrderType(currentProvince,currentOrderType);
});

$('ul').on("click","li#bottom",function(){
            currentOrderType = $(this).text().replace(/[0-9]/ig,"");
            $(this).siblings().removeClass('choose');
            $(this).addClass('choose');
            refreshOrderCountByProvinceAndOrderType(currentProvince,currentOrderType);
            refreshUserOrderInfoByProvinceAndOrderType(currentProvince,currentOrderType);
});

頁面中有多個<ul>,現在想要不同的<ul>中<li>標簽點擊相應不同的事件。

同一<ul>下的<li>設置相同的id,上述代碼中的left、bottom即為<li>的id。

這樣就能各自響應各自的事件了。

0228更新

 感覺一個ul下邊的每個li都設置一樣的id不太好。。,還是給ul加個id吧。。。如下

$('yourULID').on("click","li",function(){
            currentOrderType = $(this).text().replace(/[0-9]/ig,"");
            $(this).siblings().removeClass('choose');
            $(this).addClass('choose');
            refreshOrderCountByProvinceAndOrderType(currentProvince,currentOrderType);
            refreshUserOrderInfoByProvinceAndOrderType(currentProvince,currentOrderType);
});

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM