Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery在标记内单击div_Jquery_Html - Fatal编程技术网

jQuery在标记内单击div

jQuery在标记内单击div,jquery,html,Jquery,Html,我的HTML 您的选择器错误,请使用 $back = $(this).find('a.back'), $forward = $(this).find('a.forward'); $back.click(function (e) { e.stopPropagation(); e.preventDefault(); return gotoPage(currentPage - 1)

我的HTML


您的选择器错误,请使用

$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);
                });
$back=$(this.find('.back'), $forward=$(this.find('.forward'); $back。单击(函数(e){ e、 停止传播(); e、 预防默认值(); 返回gotoPage(当前页-1); }); $forward。单击(功能(e){ e、 停止传播(); e、 预防默认值(); 返回gotoPage(当前页面+1); });

这是所有注释的总结:)

在锚标记中嵌套div在语义上是不正确的。如果您不打算使用
元素,为什么不直接删除它呢?您总是可以将其替换为单击时不起任何作用的内容,即另一个div。您在此代码中找不到
a.back
,因为它不是
它是
div
!!只要试着找到
.back
.forward
。你应该使用新的语法事件:
$back.on(“click”,function(e){})
,这也是我说的,但没问题;)+1当我发布时,您的评论没有出现,抱歉^Grrreat!非常感谢你的帮助!
$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);
                });
$back = $(this).find('a .back'),
$forward = $(this).find('a .forward');
<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);
});