gpt4 book ai didi

javascript - 函数不从正文页面调用

转载 作者:行者123 更新时间:2023-11-30 20:37:07 25 4
gpt4 key购买 nike

我有一个文件 main.js。具有2个功能

function clockDown(scs,ids){
var countdownTimer = setInterval(function(){
$(".trf_"+ids).html(timer(scs));
scs--;
}, 1000);
}
function timer(seconds){
var seconds = seconds;
var days = Math.floor(seconds/24/60/60);
var hoursLeft = Math.floor((seconds) - (days*86400));
var hours = Math.floor(hoursLeft/3600);
var minutesLeft = Math.floor((hoursLeft) - (hours*3600));
var minutes = Math.floor(minutesLeft/60);
var remainingSeconds = seconds % 60;
if (remainingSeconds < 10) {
remainingSeconds = "0" + remainingSeconds;
}
return (days + ":" + hours + ":" + minutes + ":" + remainingSeconds);
if (seconds == 0) {
return ("Completed");
} else {
seconds--;
}
}

我将此文件包含在页面底部。在页面中间,我正在尝试调用函数,但结果为零

<li>
<script type="text/javacsript">$(document).ready(function(){ clockDown($timeLeft,$PostCoinJoinedItemsId); });</script>
</li>

我做错了什么?但是在 main.js 中调用函数运行良好

最佳答案

我已经测试过了,它工作得很好。你打错了

type="text/javacsript"

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>

<body>
<div class="trf_"></div>
<li>
<script type="text/javascript">
$(document).ready(function () {
clockDown(10, '');
});
</script>
</li>
<script>

function clockDown(scs, ids) {
var countdownTimer = setInterval(function () {
$(".trf_" + ids).html(timer(scs));
scs--;
}, 1000);
}
function timer(seconds) {
var seconds = seconds;
var days = Math.floor(seconds / 24 / 60 / 60);
var hoursLeft = Math.floor((seconds) - (days * 86400));
var hours = Math.floor(hoursLeft / 3600);
var minutesLeft = Math.floor((hoursLeft) - (hours * 3600));
var minutes = Math.floor(minutesLeft / 60);
var remainingSeconds = seconds % 60;
if (remainingSeconds < 10) {
remainingSeconds = "0" + remainingSeconds;
}
return (days + ":" + hours + ":" + minutes + ":" + remainingSeconds);
if (seconds == 0) {
return ("Completed");
} else {
seconds--;
}
}
</script>
</body>

</html>

关于javascript - 函数不从正文页面调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49711999/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com