IE8及以下版本的JCrumb Breadcrumb

时间:2012-02-01 14:44:09

标签: jquery

我使用JCrumb jQuery面包屑 - 它似乎在IE8及以下版本中无效。

当我在EI8中尝试时,我收到了这个错误:

SCRIPT65535: 源对象无效  jquery-1.6.2.min.js,第17行,第29113页

jquery的错误是“this.appendChild(a)”

有谁知道我错了或如何使这与ie8及以下兼容......?

// jCrumb initialization and useage
$('#breadCrumb').jCrumb({ maxCrumbs: 5 });

jquery.jcrumb:

(function ($) {
    $.fn.jCrumb = function (options) {
        var settings = {
            maxCrumbs: 4,
            maxMemory: 15,
            defaultClass: 'jCrumb',
            jqUI: false,
            seperator: ">"
        },
            getCrumbs = function () {
                var cookieName = "breadcrumbs=",
                    cookies = document.cookie.split(';');

                for (var i = 0; i < cookies.length; i++) {
                    var cookie = cookies[i].replace(/^\s+/, "");

                    if (cookie.indexOf(cookieName) == 0) {
                        return cookie.substring(cookieName.length, cookie.length);
                    }
                }
                return;
            },
            setCrumb = function (crumb) {
                var crumbs = getCrumbs();

                if (crumbs) {
                    var maxMemory = settings.maxMemory;
                    crumbCheck = crumbs.split('*');

                    if (crumbCheck[crumbCheck.length - 1] != crumb) {
                        crumbCheck.push(crumb);
                    }

                    if (crumbCheck.length > maxMemory) {
                        crumbCheck.splice(0, 1);
                    }

                    crumbs = crumbCheck.join('*');
                } else {
                    crumbs = crumb;
                }

                document.cookie = 'breadcrumbs=' + crumbs + '; path=/';
            },
            removeCrumb = function (crumb, index) {
                var crumbs = getCrumbs();
                if (crumbs) {
                    crumbCheck = crumbs.split('*');
                    crumbCheck.splice(index, (crumbCheck.length - index));
                    crumbs = crumbCheck.join('*');
                    document.cookie = 'breadcrumbs=' + crumbs + '; path=/';
                }

                return;
            };
        return this.each(function () {

            if (options) {
                settings = $.extend(settings, options);
            }

            setCrumb(document.title + '^' + window.location.href);

            var crumbs = getCrumbs(),
                crumbVal = "",
                crumbList = $(document.createElement('ul')).addClass(settings.defaultClass).appendTo($(this)),
                crumbListItem = "";

            if (settings.jqUI) {
                crumbList.addClass('fg-buttonset fg-buttonset-single ui-helper-clearfix');
            }

            if (crumbs) {
                crumbs = crumbs.split('*');
                startIndex = 0;

                $(crumbList).html('<li><a href="index.html" class="home">Nordjyske Fagfolk></a></li');

                if (crumbs.length > settings.maxCrumbs) {
                    startIndex = crumbs.length - settings.maxCrumbs;
                }

                for (var i = startIndex; i < crumbs.length - 1; i++) {
                    crumbVal = crumbs[i].split('^');
                    crumbListItem = $(document.createElement('li'));

                    var crumbLink = $(document.createElement('a'));
                    crumbLink.attr({ 'href': crumbVal[1] }).text(crumbVal[0]).appendTo(crumbListItem.appendTo(crumbList));
                    crumbLink.click(function () { removeCrumb($(this).text() + '^' + $(this).attr('href'), $(this).data("index")); });
                    crumbLink.data("index", i);

                    if (settings.jqUI) {
                        crumbListItem.addClass('fg-button ui-state-default ui-priority-primary');
                        if (i === 0) {
                            crumbListItem.addClass('ui-corner-left');
                            crumbLink.addClass('ui-icon ui-icon-home');
                        }
                        if (startIndex !== 0 && i === startIndex) {
                            crumbListItem.addClass('ui-corner-left');
                            crumbLink.addClass('ui-icon ui-icon-carat-1-w');
                        }
                    } else if (settings.seperator) {
                        $(document.createElement('span')).html(settings.seperator).appendTo(crumbListItem);
                    }
                }

                crumbListItem = $(document.createElement('li'));
                crumbVal = crumbs[crumbs.length - 1].split('^');
                $(document.createElement('span')).text(crumbVal[0]).appendTo($(crumbListItem).appendTo($(crumbList)));

                if (settings.jqUI) {
                    crumbListItem.addClass('fg-button ui-state-default ui-priority-primary ui-corner-right ui-state-active');
                }

                $(".fg-button:not(.ui-state-disabled)").hover(
                    function () {
                        $(this).addClass("ui-state-hover");
                    },
                    function () {
                        $(this).removeClass("ui-state-hover");
                    }
                )
            }
        });
    };
})(jQuery);

1 个答案:

答案 0 :(得分:0)

问题出在了javascript之后...... - 错误显然是我调用脚本的地方:

            if(result){ 
                $('title').text(result[1]);
            }else{
                $('title').text("JCrumb Main");
            }

应该

            if(result){ 
                document.title = result[1];
            }else{
                document.title = "JCrumb Main";
            }

相反 - 现在它就像所有IE版本中的魅力...... :-)无论如何,谢谢大家的帮助......