0

数週間前にサンプル サイトをコーディングしました。うまくいきましたが、今はうまくいきません。昨日、Chromeが更新された後(またはそう思われる)に始まりました。

コンソールの私のエラーは次のとおりです。

Uncaught TypeError: Cannot read property 'msie' of undefined
Uncaught TypeError: Object [object Object] has no method 'rating' 

どちらも、私が常に使用している jQuery プラグイン (jQuery Form、jQuery StarRating、jQuery UI など) が原因です。また、showjQueryUI で使用する要素にカーソルを合わせると、

Uncaught TypeError: Property '#<Object>' of object #<Object> is not a function 

私のJSコードは次のとおりです。

(function($){})(window.jQuery);
$(document).ready(function() {

    /* T.O.C.

    1. Top
    1.0 | Header
    1.1 | Main Menu
    1.2 | Placeholders
    2. Content
    2.1 | Left
    2.1.1 | Box covers
    3. Sidebar
    3.1 | Rates

     */
});

/* 1.0 | Top */
// 1.1 | Main Menu
function searchInput() {
    var totalWidth = 0;
    var n = parseInt(0);
    $('nav#mainMenu ul li:not(.search)').each(function() {
        totalWidth += parseInt($(this).outerWidth(true));
    });
    var inp = 919 - totalWidth;
    $('nav#mainMenu ul li.search form input').width(inp);
};

function slideMenu() {
    $('nav#mainMenu ul li:not(:first), nav#mainMenu ul li ul:not(li a)').each(function() {
        $(this).mouseenter(function() {
            $(this).children('a').addClass('active');
            var left = $(this).outerWidth(true),
                width = 0;
            if($(this).hasClass('help')) { // IF HELP
                $(this).prevAll('li').each(function() {
                    width += $(this).outerWidth(true);
                });
            } else { // ELSE
                $(this).nextAll('li').each(function() {
                    width += $(this).outerWidth(true);
                });
            }

            var width = width + 1;

            if($(this).hasClass('help')) {
                $(this).children('ul').css({ 'right':left, 'width':width });
                $(this).children('ul').show('slide', { direction: 'right' }, 250);
            } else {
                $(this).children('ul').css({ 'left':left, 'width':width });
                $(this).children('ul').show('slide', { direction: 'left' }, 250);
            }
        });
        $(this).mouseleave(function() {
            if($(this).hasClass('help')) {
                $(this).children('ul').hide('slide', { direction: 'right' }, 250, function() {
                    $(this).parent('li').children('a').removeClass('active');
                });
            } else {
                $(this).children('ul').hide('slide', { direction: 'left' }, 250, function() {
                    $(this).parent('li').children('a').removeClass('active');
                });
            }
        });
    });
};

slideMenu();

searchInput();

/* 1.2 | Placeholder */
function Placeholders() {
    if(!Modernizr.input.placeholder){

        $("input").each(
            function(){
                if($(this).val()=="" && $(this).attr("placeholder")!=""){
                    $(this).val($(this).attr("placeholder"));
                    $(this).focus(function(){
                        if($(this).val()==$(this).attr("placeholder")) $(this).val("");
                    });
                    $(this).blur(function(){
                        if($(this).val()=="") $(this).val($(this).attr("placeholder"));
                    });
                }
            });

    }
}

Placeholders();

/* 2. Content */

// 2.2.1 | Box covers
function BoxCovers() {
    $('ul.boxlist li').mouseenter(function() {
        $(this).children('div').stop().fadeIn('fast');
    });
    $('ul.boxlist li').mouseleave(function() {
        $(this).children('div').stop().fadeOut('fast');
    });

    $('.boxlist .rate').rating();
    $('.boxlist form.starRated a').attr('title','');
}

BoxCovers();

function Detailed() {
    $('ul.detailed .rate').rating();
    $('ul.detailed form.starRated a').attr('title','');

    $('ul.detailed li').each(function() {
        $(this).removeClass('grid_4').addClass('grid_14 clearfix');
        var img = $(this).children('img').attr('src'),
            img = img.replace('.jpg','-m.jpg');

        $(this).children('img').attr('src',img).addClass('grid_1');
        $(this).children('div').addClass('grid_9');

        $(this).mouseenter(function() {
            $(this).children('div').children('p.own').stop().fadeIn();
        });

        $(this).mouseleave(function() {
            $(this).children('div').children('p.own').stop().fadeOut();
        });
    });
};

Detailed();

/* 3. Sidebar */
// 3.1.  Rates
function sideRates() {
    $('section#grades div ul li').each(function() {
        var percent = $(this).children('b').text(),
            percent = percent.replace('%',''),
            percent = (percent/100),
            totalSpamWidth = $(this).children('span').width(),
            newWidth = totalSpamWidth * percent;

        $(this).children('span').width(newWidth);
    });
};

sideRates();
4

4 に答える 4

2

これは、jQuery.browser プロパティが jQuery 1.9 から削除されたことが原因です。どうやら、このブラウザー検出機能は jQuery 1.3 から非推奨になっているようですが、多くのプラグイン/ライブラリーはおそらくまだそれに依存しています (私のプロジェクトで使用するのが好きな 1 つを挙げればjQuery Tools )。

公式リファレンスについては、 http : //jquery.com/upgrade-guide/1.9/#jquery-browser-removedを参照してください。

簡単に修復するには、以前のバージョンの jQuery を使用します。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
于 2013-01-16T11:59:49.027 に答える
1

コメントの代わりに答えを得るために:

最新の jQuery を使用しています。このバージョンでは、使用しているものが削除または変更されている可能性があります。最新のものを取得するのではなく、ページを作成したバージョンを維持することをお勧めします。そうすれば、バージョンの違いによって壊れることはありません。

于 2013-01-16T09:08:15.330 に答える
0

「未定義のプロパティ 'msie' を読み取れません」

これは、jQuery が読み込まれていないことを示唆しています。開発者ツール (F12)、ネットワーク タブを使用して確認し、ページを更新して、スクリプト/リソースで 404 エラーが発生するかどうかを確認します。

于 2013-01-16T08:57:26.460 に答える
0

最新のjQueryを使用しながら、このエラーを修正できました。Superfish メニュー スクリプトを呼び出すと、次の場所から呼び出したときに「未定義のプロパティ 'msie' を読み取れません」というエラーが表示されました。

$(document).ready(function() { startScripts(); });

しかし、その後、次のように変更しました。

$(document).load(function() { startScripts(); });

エラーが消えました。これは、これが読み込み順序のタイミングの問題であることを示唆しています。

于 2013-01-17T12:07:38.490 に答える