我的HTML
<ul class="hotels-list clearfix">
<li class="hotels-list-item clearfix">
<a href="">
<div class="btn-forward forward"></div>
<div class="btn-back back"></div>
</a>
</li>
</ul>
有没有办法点击div
标记内的a
而无需点击父a
代码?
我尝试使用代码bolow但它不起作用
$back = $(this).find('a.back'),
$forward = $(this).find('a.forward');
$back.click(function (e) {
e.stopPropagation();
e.preventDefault();
return gotoPage(currentPage - 1);
});
$forward.click(function (e) {
e.stopPropagation();
e.preventDefault();
return gotoPage(currentPage + 1);
});
答案 0 :(得分:1)
您的选择器错误,请使用
$back = $(this).find('a .back'),
$forward = $(this).find('a .forward');
答案 1 :(得分:1)
<ul class="hotels-list clearfix">
<li class="hotels-list-item clearfix">
<div class="btn-forward forward"></div>
<div class="btn-back back"></div>
</li>
</ul>
$back = $(this).find('.back'),
$forward = $(this).find('.forward');
$back.click(function (e) {
e.stopPropagation();
e.preventDefault();
return gotoPage(currentPage - 1);
});
$forward.click(function (e) {
e.stopPropagation();
e.preventDefault();
return gotoPage(currentPage + 1);
});
这是所有评论的总结:)