我已經從同事(誰目前無法接觸)給了一些Javascript,並且我想知道如何實際顯示javascript在我的網頁上創建的編號。 我已經加載使用在網站上顯示javascript的問題
<SCRIPT language=JavaScript src="https://www.mywebsite.com/java/counter.js"></SCRIPT>
但是我不知道有什麼用HTML實際給我結果的JavaScript。
var currStr = 0;
var targetStr = 0;
var animTimer = null;
$(document).ready(function() {
currStr = calculateCups();
$('.tea-count > .figure').html(currStr.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
setInterval(anim, 1000);
});
function anim()
{
targetStr = calculateCups();
animTimer = setInterval(function()
{
if (currStr < targetStr) {
currStr += 155;
$('.tea-count > .figure').html(currStr.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
}
if (currStr >= targetStr) {
clearInterval(animTimer);
}
}, 25);
}
function calculateCups()
{
var cupsNumber = 165000000;
var date = new Date();
var hours = date.getUTCHours()*60*60;
var minutes = date.getUTCMinutes()*60;
var seconds = date.getUTCSeconds();
return Math.round((cupsNumber/86400)*(hours+minutes+seconds));
}
您的幫助非常感謝!
請參閱此鏈接https://stackoverflow.com/questions/17753241/display- javascript-as-code-snippet –
你試過用
標籤? – madalinivascu
你問如何執行它或如何顯示它?首先請你的同事做什麼。其次,研究Javascript如果你不明白的代碼。 – ADyson