我的 HTML 代码是这样的:
<div id="divAutoPlay" onclick="autoPlay(0);">
<ul>
<li><a href="javascript:;" onClick="autoPlay(3);">3 Times</a></li>
<li><a href="javascript:;" onClick="autoPlay(5);">5 Times</a></li>
<li><a href="javascript:;" onClick="autoPlay(10);">10 Times</a></li>
</ul>
</div>
ul
是div
悬停时出现的弹出窗口以选择自动时间,如果单击div
自身(在进度弹出窗口中不显示),则自动播放停止。
function autoPlay(playCount){
if(autoPlayCount>0)
autoPlayCount=playCount;
else if(playCount>0){
setTimeout(function(){
autoPlayCount=playCount;
$('#divPlay').click();
}, 2000);
}
// don't know how to add stopPropogation effectively
//event.stopPropagation();
// commented codes doesn't worked
/*
if (event.stopImmediatePropagation){
event.stopImmediatePropagation();
}else if(window.event){
window.event.cancelBubble=true;
}
*/
// for this also changed function definition to pass 'event' onClick="autoPlay(event,10);"
}
问题是,如果我点击 n 次 on li
,onclick
ondiv
也会被触发,使播放停止。