Javascript JS播放器---错误:我的返回false不适用于IE10,但适用于所有其他浏览器
嗨,我用javascript制作了一个mp3播放器,它在除IE10之外的所有浏览器上都能正常工作 页面示例:(尝试单击歌曲) 但是IE10遵循链接并忽略了之前的脚本 这是我的剧本:Javascript JS播放器---错误:我的返回false不适用于IE10,但适用于所有其他浏览器,javascript,jquery,Javascript,Jquery,嗨,我用javascript制作了一个mp3播放器,它在除IE10之外的所有浏览器上都能正常工作 页面示例:(尝试单击歌曲) 但是IE10遵循链接并忽略了之前的脚本 这是我的剧本: var list = $("#playlist").find("a:not(.songLink)"); listNC=new Array(); for (var i=0;i<list.length;i++) { // we get all the song lis
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!**
}
};
var list=$(“#播放列表”).find(“a:not(.songLink)”;
listNC=新数组();
对于(var i=0;i你有很多混搭jQuery与常规DOM代码的方法,这有点让人困惑。我认为它只是在其他浏览器中工作,这是你运气不好。最终,我相信IE在调用preventDefault
时会出错,因为它有不同的事件模型,你没有使用升级的jQuery事件。这意味着preventDefault
不执行其工作,并且由于错误而从未到达返回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
});
var listNC=[],
现在的
$(“#播放列表”)
.find('a:not(.songLink'))
.每项功能(i){
var$this=$(this);
美元这个
.attr('rel',i)
.parent()
.parent()
.prepend(“”);
listNC[i]=girlify($this.attr('href');
})
.on('click',函数(e){
soundManager.stopAll();
当前=$(this.attr('rel');
lire_电流();
//事件控制:
e、 preventDefault();//防止链接被跟踪
//我认为你不需要下面两行中的任何一行:
e、 stopPropagation();//防止事件冒泡…可能不是您想要的
return false;//原因与调用e.preventDefault()e.stopPropagation()相同……可能不是您想要的
});
当然,我不能测试它,但我想它会满足你的要求。我在网上发布了你的代码,你是对的,这是一个旧脚本js混合了jquery,但是它仍然不能与遵循linksWell的IE10一起工作,我没有办法测试。但是e.preventDefault();
是您希望jQuery事件处理程序内部阻止浏览器跟随链接的内容。您是否看到IE10在开始跟随链接之前报告了任何错误?处理程序或它所利用的代码中的任何地方都可能有错误(soundManager
代码或lire\u current
)。任何此类错误都会阻止事件处理。请尝试使e.preventDefault()成为
click handling函数的第一行。如果浏览器没有遵循链接,那么您知道之后某个地方发生了错误。IE10控制台在关闭之前没有错误遵循链接。它在所有其他浏览器上都可以工作。在所有其他浏览器中工作并不意味着什么。IE因不符合标准的问题而臭名昭著通常出现在其他浏览器中。请检查我对最后一条评论的编辑。