Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
388 views
in Technique[技术] by (71.8m points)

one Jquery is not working on the second click

this is the code

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


});

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.

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 divs this 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 take a look here please, this the site with function one() in case i change to on() when you click on div it block haiders.imcserver.ro/telugu you can take a look at the second case with on() here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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");
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...