//html代码:
- 冰箱冷柜
- 洗衣机
- 电视
- 空调
- 热水器
- 厨房电器
- 生活家电
//JS代码:
$('.hot_nav').on('click','.hot_nav>ul>li',function(){
var htype=$(this).attr('class');
console.log(htype);
loadhot(htype);
});
//ul下的li无法绑定,给ul加个class却能找到,已经确定ul为唯一ul
$('.hot_nav').on('click','.hot_list>li',function(){
var htype=$(this).attr('class');
console.log(htype);
loadhot(htype);
});
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
因为. hot_nav的子节点中并没有. hot_nav
如果是异步加载,最好是委托到body上,
$('body').on('click', '.hot_list li', function() {
//code
})