我已經使用類似職位的代碼 Random Number Effect In Jquery .. 動畫隨機數,結果http://jsfiddle.net/ZDsMa/94/ ...沒有運行
現在我寫在一個文件中的PHP(index.php
)全碼HTML和jQuery和放置在我的服務器...
<html>
<title>Randomize Number</title>
<head>
<style type="text/css">
#output {
margin: 20px;
padding: 20px;
background: gray;
border-radius: 10px;
font-size: 80px;
width: 160px;
color: red;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script>
var output, started, duration, desired;
// Constants
duration = 5000;
desired = '50';
// Initial setup
output = $('#output');
started = new Date().getTime();
// Animate!
animationTimer = setInterval(function() {
// If the value is what we want, stop animating
// or if the duration has been exceeded, stop animating
if (output.text().trim() === desired || new Date().getTime() - started > duration) {
console.log('animating');
// Generate a random string to use for the next animation step
output.text('' + Math.floor(Math.random() * 990)
);
} else {
console.log('animating');
// Generate a random string to use for the next animation step
output.text('' + Math.floor(Math.random() * 990)
);
}
}, 1000);
</script>
</head>
<body>
<div id="output">-</div>
</body>
</html>
的動畫隨機數不顯示(JScript中不運行,只用框 ' - ' characher/CSS)
這有什麼錯我的代碼?
我不明白攪拌機,我應該在哪裏放置代碼「$(文件)。就緒()」上面..? – andry 2013-03-22 04:46:45
@andry:http://stackoverflow.com/questions/13062246/when-should-i-use-jquerys-document-ready-function – Blender 2013-03-22 04:48:12