功能不是从正文页面调用

时间:2018-04-07 21:07:21

标签: javascript jquery

我有一个文件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中的函数效果很好

1 个答案:

答案 0 :(得分:1)

我已经过测试,而且效果很好。你有一个错字

type="text/javacsript"

&#13;
&#13;
<!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>
&#13;
&#13;
&#13;