本文介绍了一个Jquery在第二次点击时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是代码

jQuery(document).ready(function(){
    jQuery('.post_box').one('click', function(e) {
        jQuery(this).find(".read_more").trigger("click");
    });


});

当我单击div(post_box)时,它会触发位于(post_box)的子div中具有类(read_more)的链接(弹出灰色框),现在它可以正常工作,但是当我关闭链接时出现问题(灰色框),然后再次在div(post_box)上单击它不起作用,我必须刷新页面才能将其单击.

when I click on the div (post_box) it trigger a link (pop up greybox)located in sub div of (post_box) which has the class (read_more), right now it work good but the problem when i close the link(greybox), and click againe on the div (post_box) it doesn't work, I have to refresh the page to click it.

如果我改用on()函数,则在第一次单击时将触发该链接并被阻止,我认为由于子div,它触发了一个以上的链接这是html代码

if i put the on() function instead , on the first click it will trigger the link and get blocked, i think it trigger the link more than one because of the sub divsthis is the html code

`
<div class="post_box" >
    <div class="post_box_top">
        <div class="post_box_center">
            <div class="post_box_content">

                <div class="post_date">

                </div>
                <div class="post_content">

              <?php   echo   $content_post = get_post(get_the_ID());?>

                </div>
                <div class="post_footer">
                    <a href="<?php the_permalink();?>" title="<?php the_title(); ?>" class="read_more"  rel="gb_pageset[search_sites]"  data-greybox-type="iframe">Read more</a>
               // this the link i should trigger when someone click on the <div class="post_box">
               </div>
            </div>
        </div>
    </div>
</div>`

ec2-107-22-235-75.compute-1.amazonaws.com请在此处查看,该站点具有函数one(),以防万一当您单击div时我更改为on()会阻止生成器.imcserver.ro/telugu,您可以在这里使用on()查看第二种情况

推荐答案

这是one()方法的正确行为-它仅将事件绑定一次.

This is correct behaviour for the one() method - it only binds the event once.

如果要在页面生命周期内绑定事件,则需要使用on()代替.

You need to use on() instead if you want the event bound for the life of the page.

jQuery('.post_box').on('click', function(e) {
    jQuery(this).find(".read_more").trigger("click");
});

这篇关于一个Jquery在第二次点击时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 21:33