0

Hi iveは、JavaScriptを使用してmp3プレーヤーを作成しました。これは、IE10を除くすべてのブラウザーで完全に機能します。

ページの例:http ://www.mupiz.com/noon (曲をクリックしてみてください)

しかし、IE10はリンクをたどり、前にスクリプトを無視します...

これが私のスクリプトです:

    var list = $("#playlist").find("a:not(.songLink)");
    listNC=new Array();


    for (var i=0;i<list.length;i++) { // we get all the song


        list[i].rel = i; 

        $(list[i]).parent().parent().prepend("<td class='notplayed' width='25px'><img src='../../images/lecteur-B-playlist-play.png' style='z-index:10000'/></td>");
        listNC[i]=girlify(list[i].href);


        list[i].onclick = function(event) { // onclick on each link


                   if($(this).attr('class')!="songLink"){
            soundManager.stopAll(); 
            current = this.rel; 



                event.preventDefault();
                        lire_current(); // this play the song
                       return false; // **this does not work!**

                       }

        };

これはCSSの専用部分です

4

1 に答える 1

0

jQueryと通常のDOMコードを組み合わせたものがたくさんあり、混乱を招きます。私はそれがあなたの側の運が悪い他のブラウザでしか機能していないと思います。最終的に、IEはpreventDefault異なるイベントモデルを持ち、平準化されたjQueryイベントを使用していないため、への呼び出しでエラーが発生していると思います。これはpreventDefault、その仕事をしないことを意味しreturn false、エラーのために到達することはありません。

抽出したコードを次のように変更します。

var listNC = [],
    current;

$('#playlist')
    .find('a:not(.songLink)')
    .each(function (i) {
        var $this = $(this);

        $this
            .attr('rel', i)
            .parent()
                .parent()
                    .prepend('<td class="notplayed" width="25px"><img src="../../images/lecteur-B-playlist-play.png" style="z-index:10000"/></td>');

        listNC[i] = girlify($this.attr('href'));
    })
    .on('click', function (e) {
        soundManager.stopAll();
        current = $(this).attr('rel');

        lire_current();

        // Event control:
        e.preventDefault(); //keeps link from being followed

        //I don't think you want either of these next two lines:
        e.stopPropagation(); //keeps event from bubbling...probably not what you want
        return false; //causes same as calling e.preventDefault() e.stopPropagation()...probably not what you want
    });

もちろんテストはできませんでしたが、思い通りに動作すると思います。

于 2013-01-10T01:20:00.780 に答える