search

Home  >  Q&A  >  body text

javascript - click event of parent element not working

The cloud-zoom plug-in I use. The internal structure is as follows

<li title="红色">
                                <a href="images/bag-img_03.png" class='cloud-zoom-gallery'  title='Red' rel="useZoom: 'zoom1', smallImage: 'images/bag-img_03.png' ">
                                    <img src="images/bag-img_03.png" alt="" mid="images/bag-img_03.png" big="images/bag-img_03.png" />
                                </a>
</li>
a标签插件里面有个点击事件

if($(this).is('.cloud-zoom-gallery')) {

            opts = $.extend({}, c, d);
            $(this).data('relOpts', opts);
            $(this).bind('click', $(this), function(a) {
                var b = a.data.data('relOpts');
                $('#' + b.useZoom).data('zoom').destroy();
                $('#' + b.useZoom).attr('href', a.data.attr('href'));
                $('#' + b.useZoom + ' img').attr('src', a.data.data('relOpts').smallImage);
                $('#' + a.data.data('relOpts').useZoom).CloudZoom();
                return false
            })
            
            然后我写的li的事件就失效了。 上面也没阻止这个冒泡事件啊。我把return false去掉就可以了。但是A标签会造成页面的跳转。我又把href改成了别的属性、这样会不会某些地方出错。
            或者有没有别的方法可以让li的事件触发。 
typechotypecho2699 days ago837

reply all(2)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-06-26 10:52:11

    To prevent the default event of a tag, you can use event.preventdefault()

    http://www.w3school.com.cn/js...

    An article is written like the picture above

    return falseDon’t use it casually, write whatever you want to prevent, and don’t let bad habits make you step on your own mistakes in the future

    For details, please check
    http://www.jb51.net/article/4...

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-06-26 10:52:11

    If you don’t want to jump, use <a href="javascript:"></a> No, it will be fine. If you return false in the event, the event will be invalid.

    reply
    0
  • Cancelreply