所有你需要的是從您發佈的問題,這個例子: http://jsfiddle.net/526hM/
,它重視在onload的部分是這樣的:
$(document).ready(function(){
...
setTimeout(animator, updatesPerSecond);
}
您只需將此animator
函數附加到按鈕上即可。要在3秒內發生效果,請更新時序變量。
HTML:
<progress max="200" value="0"></progress>
<button id="theButton">Start!</button>
腳本:
$(document).ready(function(){
var msecsPerUpdate = 1000/60; // # of milliseconds between updates, this gives 60fps
var progress = $('progress');
var duration = 3; // secs to animate for
var interval = progress.attr('max')/(duration*1000/msecsPerUpdate);
var animator = function(){
progress.val(progress.val() + interval);
if (progress.val() + interval < progress.attr('max')){
setTimeout(animator, msecsPerUpdate);
} else {
progress.val(progress.attr('max'));
}
}
$('#theButton').click(function(e) {
e.preventDefault();
animator();
});
});
演示:http://jsfiddle.net/526hM/28/
我不能得到這個工作,我不知道爲什麼。 jsfiddle中的代碼直接插入嵌套在腳本標記中的文檔頭部,但它仍然刷新我的頁面並且什麼都不做。 http://lrroberts0122.github.com/WDF/html5_form.html是一個包含我所有代碼的頁面,包括插入的js。感謝您的幫助。 – 2012-08-17 02:37:41
你的頁面上有jQuery嗎? 如果您的網頁也可公開訪問,則可以發佈您的網頁。 – 2012-08-17 02:38:27
你需要在你的頁面中包含jQuery,它是一個庫,使得它更容易在JavaScript中進行編碼。您只需在**上述腳本之前在您的頭**中加入另一個腳本標記: '' – 2012-08-17 02:42:50