0

ここに私の jsFiddle があります: http://jsfiddle.net/markrummel/vPcrX/

このコードは、Chrome、Firefox、Safari、および IE 10 で機能しますが、IE 7、8、または 9 では機能しません。

IE 10 の Developer Tool を使用してテストしましたが、IE 7、8、または 9 で最初に開いたときには機能しませんでした。しかし、Developer Tool を開いた後、IE 7、8、および 9 で機能し始めました。Microsoft の Virtual PCを介して古い IE ブラウザでもテストしましたが、ローテータは機能しません。

ここでページ全体を見ることができます: http://melaniejaderummel.com . ただし、削除されたjsFiddleでは機能しないため、問題は jQuery コードに限定されていると思います。

あなたが提供できるどんな助けも大歓迎です!

私のHTML:

<div id="testimonials">
    <p data-testimonial="1">“Testimonial Content” – Julie S.</p>
    <p data-testimonial="2">“Testimonial Content” – Melissa D.</p>
    <!--repeated; 10 total testimonials-->
</div>

関連する CSS:

#testimonials p {display:none;}

そして最後に、これが私のjavascriptです:

$(document).ready(function () {

    var shownTestimonials = [];

    displayTestimonials(shownTestimonials);

    function displayTestimonials(shownTestimonials) {
        var totalTestimonials = 10;

        console.log(shownTestimonials);
        //console.log(shownTestimonials.length);

        if (shownTestimonials.length == 0 || shownTestimonials.length == totalTestimonials) {
            var shownTestimonials = [];
        }

        function getNewTestimonial(totalTestimonials) {
            return Math.floor(Math.random() * totalTestimonials) + 1; //random number between 1 and 10
        }

        var currentTestimonial = $('#testimonials p.visible').attr('data-testimonial');
        var newTestimonial = getNewTestimonial(totalTestimonials);

        console.log(currentTestimonial);

        if (currentTestimonial == null) {
            $('#testimonials p[data-testimonial="' + newTestimonial + '"]').addClass('visible').fadeIn(700);
            shownTestimonials.push(newTestimonial);
        } else {

            var newExists = 1;

            while (newExists > -1) {
                var newTestimonial = getNewTestimonial(totalTestimonials);
                var newExists = $.inArray(newTestimonial, shownTestimonials)
                console.log(newExists);
            }

            $('#testimonials p[data-testimonial="' + currentTestimonial + '"]').removeClass('visible').fadeOut(600);
            setTimeout(function () {
                $('#testimonials p[data-testimonial="' + newTestimonial + '"]').addClass('visible').fadeIn(700);
                shownTestimonials.push(newTestimonial);
            }, 700);
        } //end else

        setTimeout(function () {
            displayTestimonials(shownTestimonials);
        }, 12000);
    } //end displayTestimonials();

}); //end $(document).ready
4

1 に答える 1

1

console.logステートメントを削除またはコメントアウトします。コンソールが開いていない限り、IEはそれらをチョークします(開発ツールを備えたIEのバージョンで)。

このMSDNの記事ごと:

開発者ツールを開かない限り、出力を表示できないことに注意してください。[コンソール] タブまたは [スクリプト] タブでコンソール出力を確認できます。デバッグにコンソールを使用する場合は注意してください。本番環境に移行するときにコード内にコンソール オブジェクトへの呼び出しを残し、開発者ツールが表示されていない場合、コンソールが定義されていないことを示すエラー メッセージが表示されます。エラー メッセージを回避するには、コードからすべてのコンソール メソッド呼び出しを削除するか、メソッドを呼び出す前にコンソールが存在することを確認するチェックを追加する必要があります。

于 2013-06-09T01:49:02.760 に答える