JS播放器——错误:我的返回错误不与IE10工作,但与所有其他浏览器工作

JS Player --- Err : My Return false doesnt work with IE10 but work with all other browser

本文关键字:工作 错误 浏览器 其他 IE10 我的 返回 JS 播放器      更新时间:2023-09-26

我用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的专用部分

你有很多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
    });

我当然不能测试它,但我认为它会做你想要的。