原谅多余的代码,将在适当的时候进行整理。

一切似乎都有效,但是,当您单击链接的内容已经“处于活动状态”之后,则什么也没有发生。

我敢肯定这很简单,但我看不到。

编辑:以下代码现在可在FF和Chrome中使用,但在IE8中不可用。有任何想法吗?

$(function(){
            //initialize active link to not have a link on ready.
            var linkId = $('#pricing_body div.active').attr('id');
            var activeLink = $('#pricing_nav ul li#'+linkId+' a'); //just the link itself.
            activeLink.parent().addClass('activeSection');
            //var activeLinkContents = activeLink.parent().html(); //the link contained in the the list item and it's contents.
            //alert(activeLinkContents);
            var linkContents = activeLink.html(); //text content of the link.
            activeLink.parent().html(linkContents);

            //when link is clicked, store it's text for assignment after <a> is stripped out.
            $('#pricing_nav ul li a').live('click',function(){
                var clickedId = $(this).parent().attr('id');
                var clickedLinkContents = $(this).html();
                $(this).parent().addClass('activeSection');
                $(this).parent().html(clickedLinkContents); //replaces <a><span>name</span></a> with just the span and text.

                //fadeOut active div and give it inactive class. get list item with same id as div we are fading out.
                $('#pricing_body div.active').fadeOut('500',function(){
                    $(this).removeClass('active').addClass('inactive');
                    var divId = $(this).attr('id');
                    var sisterLink = $('#pricing_nav ul li#'+divId);
                    sisterLink.removeClass('activeSection');
                    sisterLink.html('<a href="#">'+sisterLink.html()+'</a>'); //put link in between <li>.

                    //fadeIn the div with id of the link that has been clicked.
                    $('#pricing_body div#'+clickedId).fadeIn('500',function(){
                        $(this).addClass('active').removeClass('inactive');
                        var newActive = $('#pricing_nav ul li#'+clickedId);
                    });
                });
            });
        });

最佳答案

使用live方法将事件附加到元素。 Here是文档。

关于javascript - jQuery操作触发一次,但不会触发一次,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3781983/

10-10 00:17