大家好, 请牛人们指点小弟一下javascript。我希望页面加载5秒后播放一个声音文件。下面是我的代码。不过不起作用。请牛人们指点
<html>
<head>
<script type="text/javascript">
function doTimer(length, resolution, oninstance, oncomplete)
{
var steps = (length / 100) * (resolution / 10),
speed = length / steps,
count = 0,
start = new Date().getTime();
function instance()
{
if(count++ == steps)
{
oncomplete(steps, count);
}
else
{
oninstance(steps, count);
var diff = (new Date().getTime() - start) - (count * speed);
window.setTimeout(instance, (speed - diff));
}
}
window.setTimeout(instance, speed);
}
doTimer(5000, 20, function(steps)
{
},
function() {
document.getElementById('audiotag1').play();
}
);
</script>
<script type="text/javascript">
function play_single_sound() {
document.getElementById('audiotag1').play();
}
</script>
</head>
<body>
Timer out
<audio id="audiotag1" src="https://www.dropbox.com/s/0kf457qwu6zh5q4/warning_alarm.mp3" preload="auto"></audio>
<a href="javascript:play_single_sound();">warning_alarm</a>
</body>
</html>
--
FROM 108.75.191.*