Javascript无法使用jquery库1.9.1

时间:2013-09-13 14:00:22

标签: javascript jquery jquery-plugins jquery-animate javascript-framework

我正在努力让这个工作与jquery库的更高版本之一兼容。在我使用1.3.2版本之前,我想暂时将该版本更新到1.9.1。我运行了一些测试,发现有一些javascript部分也需要更新,但似乎无法弄明白 - 所以我把它交给你们所有人 - 你能帮我解决这个问题吗?

修改 我有三个主要区域中的两个给我带来麻烦...我将在下面提供我认为问题可能存在的地方......其中一个部分已经解决但我仍在努力解决以下这两个部分。

JAVASCRIPT - 第1部分

$(document).ready(function () {

    $('.rate_widget').each(function (i) {
        var widget = this;
        var out_data = {
            widget_id: $(widget).attr('id'),
            fetch: 1
        };
        $.post(
            '--Ratings/ratings.php',
        out_data,

        function (INFO) {
            $(widget).data('fsr', INFO);
            set_votes(widget);
        },
            'json');
    });

    $('.ratings_stars').hover(

    function () {
        $(this).prevAll().andSelf().addClass('ratings_over');
        $(this).nextAll().removeClass('ratings_vote');
    },

    function () {
        $(this).prevAll().andSelf().removeClass('ratings_over');
        set_votes($(this).parent());
    });

    $('.ratings_stars').bind('click', function () {
        var star = this;
        var widget = $(this).parent();

        var clicked_data = {
            clicked_on: $(star).attr('class'),
            widget_id: $(star).parent().attr('id')
        };
        $.post(
            '--Ratings/ratings.php',
        clicked_data,

        function (INFO) {
            widget.data('fsr', INFO);
            set_votes(widget);
        },
            'json');
    });

});

function set_votes(widget) {

    var avg = $(widget).data('fsr').whole_avg;
    var votes = $(widget).data('fsr').number_votes;
    var exact = $(widget).data('fsr').dec_avg;

    window.console && console.log('and now in set_votes, it thinks the fsr is ' + $(widget).data('fsr').number_votes); /* ===== <-- Here ===== */

    $(widget).find('.star_' + avg).prevAll().andSelf().addClass('ratings_vote');
    $(widget).find('.star_' + avg).nextAll().removeClass('ratings_vote');
    $(widget).find('.total_votes').text(votes + ' votes recorded (' + exact + ' rating)');
}

JAVASCRIPT - 第2部分

$(function () {
    $('input.field').focus(function () {
        if (this.title == this.value) {
            this.value = '';
        }
    })
        .blur(function () {
        if (this.value == '') { /* ===== <-- Here ===== */
            this.value = this.title;
        }
    });
    var currentPage = 1;
    $('#slider_profile .buttons_profile span').live('click', function () {
        var timeout = setTimeout(function () {
            $("img").trigger("slidermove") /* ===== <-- Here ===== */
        }, 100);

        var fragments_count = $(this).parents('#slider_profile:eq(0)').find('.fragment_profile').length;
        var fragment_width = $(this).parents('#slider_profile:eq(0)').find('.fragment_profile').width();
        var perPage = 1;
        var numPages = Math.ceil(fragments_count / perPage);
        var stepMove = fragment_width * perPage;
        var container = $(this).parents('#slider_profile:eq(0)').find('.con_profile');
        var firstPosition = 0;
        var lastPosition = -((numPages - 1) * stepMove);
        if ($(this).hasClass('next')) {
            currentPage++;
            if (currentPage > numPages) {
                currentPage = 1;
                container.animate({
                    'left': firstPosition
                });
                return;
            }; /* ===== <-- Here ===== */
            container.animate({
                'left': -((currentPage - 1) * stepMove)
            });
        }; /* ===== <-- Here ===== */

        if ($(this).hasClass('prev')) {
            currentPage--;
            if (currentPage < 1) {
                currentPage = numPages;
                container.animate({
                    'left': lastPosition
                });
                return;
            }; /* ===== <-- Here ===== */
            container.animate({
                'left': -((currentPage - 1) * stepMove)
            });
        }; /* ===== <-- Here ===== */
    });
});

我可能在我标记(&lt; - Here)旁边的地方完全错了,我认为这是需要修复的问题。考虑到所有这些,有人可以帮我弄清楚如何使用最新版本的jquery 1.9.1来使这些部件工作吗?

1 个答案:

答案 0 :(得分:1)

首先,试试这个

JAVASCRIPT - 第1部分

$(document).ready(function () {
    $('a.head').click(function () {
        var a = $(this);
        var section = a.attr('href');
        section.removeClass('section');
        $('.section').hide();
        section.addClass('section');
        if (section.is(':visible')) {
            section.slideToggle(); /* ===== <-- 400 is the default duration ===== */
        } else {
            section.slideToggle();
        }
    });
});

JAVASCRIPT - 第2部分

$(document).ready(function () {
    $('.rate_widget').each(function () {
        var widget = $(this);
        var out_data = {
            widget_id: widget.attr('id'),
            fetch: 1
        };
        $.post(
            '--Ratings/ratings.php',
        out_data,

        function (INFO) {
            widget.data('fsr', INFO);
            set_votes(widget);
        },
            'json');
    });

    $('.ratings_stars').hover(function () {
        $(this).prevAll().andSelf().addClass('ratings_over');
        $(this).nextAll().removeClass('ratings_vote');
    }, function () {
        $(this).prevAll().andSelf().removeClass('ratings_over');
        set_votes($(this).parent());
    });

    $('.ratings_stars').bind('click', function () {
        var star = $(this);
        var widget = star.parent();
        var clicked_data = {
            clicked_on: star.attr('class'),
            widget_id: star.parent().attr('id')
        };
        $.post(
            '--Ratings/ratings.php',
        clicked_data,

        function (INFO) {
            widget.data('fsr', INFO);
            set_votes(widget);
        },
            'json');
    });

});

function set_votes(widget) {

    var avg = widget.data('fsr').whole_avg;
    var votes = widget.data('fsr').number_votes;
    var exact = widget.data('fsr').dec_avg;

    console.log('and now in set_votes, it thinks the fsr is ' + widget.data('fsr').number_votes);

    widget.find('.star_' + avg).prevAll().andSelf().addClass('ratings_vote');
    widget.find('.star_' + avg).nextAll().removeClass('ratings_vote');
    widget.find('.total_votes').text(votes + ' votes recorded (' + exact + ' rating)');
}

JAVASCRIPT - 第3部分

$(function () {
    $('input.field').focus(function () {
        if (this.title == this.value) {
            this.value = '';
        }
    }).blur(function () {
        if (this.value === '') { /* ===== <-- Here ===== */
            this.value = this.title;
        }
    });
    var currentPage = 1;
    $(document).on('click', $('#slider_profile .buttons_profile span'), function () {
        var timeout = setTimeout(function () {
            $("img").trigger("slidermove"); /* ===== <-- Here ===== */
        }, 100);

        var fragments_count = $(this).parents('#slider_profile:eq(0)').find('.fragment_profile').length;
        var fragment_width = $(this).parents('#slider_profile:eq(0)').find('.fragment_profile').width();
        var perPage = 1;
        var numPages = Math.ceil(fragments_count / perPage);
        var stepMove = fragment_width * perPage;
        var container = $(this).parents('#slider_profile:eq(0)').find('.con_profile');
        var firstPosition = 0;
        var lastPosition = -((numPages - 1) * stepMove);
        if ($(this).hasClass('next')) {
            currentPage++;
            if (currentPage > numPages) {
                currentPage = 1;
                container.animate({
                    'left': firstPosition
                });
                return;
            }
            container.animate({
                'left': -((currentPage - 1) * stepMove)
            });
        }

        if ($(this).hasClass('prev')) {
            currentPage--;
            if (currentPage < 1) {
                currentPage = numPages;
                container.animate({
                    'left': lastPosition
                });
                return;
            }
            container.animate({
                'left': -((currentPage - 1) * stepMove)
            });
        }
    });
});