0

我的问题就像标题说当我点击“hello number 2”div.header 时我的点击第一次触发。第一个是消失并从 DOM 中删除。然后在最后一个新的出现。我不明白为什么当我单击“hello number 3”标题时它不重复相同的过程。

提前致谢。这是一个fid。

http://jsfiddle.net/h8S9w/2/

    var x = 3;
    var newDiv;
    var firstHeader;
    var firstInfo;
    var lastHeader;
    var lastInfo;
    $(document).ready(function(){
        $('div.header').click(pseudoakkordeon);
    });
    function pseudoakkordeon(){
            x += 1;
            active = $(this);
            firstHeader= $('div.page div.header:first-child');
            firstInfo = $('div.page div.info:first-child');
            lastHeader = $('div.page div.header:last-child');
            lastInfo = $('div.page div.info:last-child');
            $('div.info').stop(true, true).slideUp(1000);
            active.next().stop(true, true).slideDown(1000, function(){
                firstHeader.slideUp(300, function(){
                    firstHeader.remove();
                    firstInfo.remove();
                    newDivx = $('div.page').append('<div class="header"> <p>Hallihalo Number ' + x + '</p></div><div class="info"><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hen</p></div>');

                    $(newDivx).live('click', pseudoakkordeon);
                });
            });
    };
4

2 回答 2

2

您必须用 on 方法替换 click 方法。所以现在的代码是:

$(document).ready(function(){
    $(document).on('click', 'div.header', pseudoakkordeon);
});

用这个新代码看看你的小提琴:http: //jsfiddle.net/h8S9w/5/

编辑:我:first-child.first method. 看看这个新小提琴:http: //jsfiddle.net/h8S9w/7/

于 2013-07-19T08:43:27.580 回答
0

你可以改变

firstHeader.slideUp(300, function() 

$(document).slideUp(300, function() 
于 2013-07-19T08:52:07.250 回答