为什么 JQuery with SetInterval 在 Firefox 上不起作用?

Why JQuery with SetInterval won't work on Firefox?

我正在尝试学习 JQuery 运行我在 Internet 上找到的处理 SetInterval 或 Settimeout 的示例代码,但它们不会 运行 或工作。例如,我有以下简单代码,但它不会 运行 甚至不会给我错误消息。

<!DOCTYPE html>
<html>
<head>
<title>testing</title>

<script type="text/javascript"> 
$(document).ready(function(){
setInterval(function() {
var number = 1 + Math.floor(Math.random() * 333);
$('#here').load(number);
},
1000);
});
</script>

</head>
<body>

<div id="here">dynamic content ?</div>

</body>  
</html>

您首先错过了添加 jquery 库,其次您应该使用 .text() 函数而不是 .load() 函数。

.load() 函数应该用于 ajax 方法。

应牢记的基本规则之一是始终将 javascript 代码放在页面末尾和正文标记结束之前

 $(document).ready(function() {
        setInterval(function() {
          var number = 1 + Math.floor(Math.random() * 333);
          $('#here').text(number);
        }, 1000);
      });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
  <head>
    <title>testing</title>
  </head>
  <body>
    <div id="here">dynamic content ?</div>
  </body>
</html>