无法使用JavaScript刷新DIV

问题描述 投票:0回答:1

我想在10秒内自动刷新某些DIV(darksky小部件id =“ 1”)。

我尝试了很多次,但是失败了。请参阅下面的内容,并注释出什么是逻辑错误。

这里是我可怜的代码。

function autoRefresh_sample_div2() {
  var currentLocation2 = window.location;
  $("#1").fadeOut('slow').load(currentLocation2 + ' #1').fadeIn("slow");
}
setInterval('autoRefresh_sample_div2()', 10000); //10 seconds
<div class="row col-lg-9">
  <div class="col-lg-1">
    <table class="table">
      <thead class="thead-dark">
        <tr>
          <th scope="col" style="text-align: center">#</th>
        </tr>
      </thead>
    </table>
  </div>
  <div class="col-lg-8 mb-2">
    <table class="table">
      <thead class="thead-dark">
        <tr>
          <th scope="col" style="text-align: center">Graph</th>
        </tr>
      </thead>
    </table>
  </div>
  <div class="col-lg-3 mb-2">
    <table class="table">
      <thead class="thead-dark">
        <tr>
          <th scope="col" style="text-align: center">Weather NOW</th>
        </tr>
      </thead>
    </table>
  </div>
  <div class="col-lg-1 my-auto">
    <h1 class="display-4 text-center">1</h1>
  </div>
  <div class="col-lg-8"><iframe class="embed-responsive embed-responsive-21by9" src="http://naver.com/"></iframe></div>
  <div class="col-lg-3 my-auto" id="1">
    <script type='text/javascript' src='https://darksky.net/widget/default-small/36.2385,127.2047/ca12/en.js?width=100%&height=70&title=Full Forecast&textColor=333333&bgColor=FFFFFF&transparency=false&skyColor=undefined&fontFamily=Default&customFont=&units=ca'></script>
  </div>

</div>
javascript jquery html refresh
1个回答
0
投票

我正在处理此代码

const weather = new URL('https://darksky.net/widget/default-small/36.2385,127.2047/ca12/en.js?width=100%&height=70&title=Full Forecast&textColor=333333&bgColor=FFFFFF&transparency=false&skyColor=undefined&fontFamily=Default&customFont=&units=ca');

const reloadWeather = () => {
  $('script[id="weather"]').remove();
  weather.searchParams.set("rdn", new Date().getTime())
  $('<script id="weather">').attr('src', weather).appendTo('head');
};

let tId;
$(function() {
  $("head").on("load", "#weather", () => {
    $("#customize-script-container").fadeIn("slow");
  })
  tId = setInterval(() => {
    $("#customize-script-container").fadeOut('slow', reloadWeather)
  }, 10000);
  reloadWeather()
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="row col-lg-9">
  <div class="col-lg-1">
    <table class="table">
      <thead class="thead-dark">
        <tr>
          <th scope="col" style="text-align: center">#</th>
        </tr>
      </thead>
    </table>
  </div>
  <div class="col-lg-8 mb-2">
    <table class="table">
      <thead class="thead-dark">
        <tr>
          <th scope="col" style="text-align: center">Graph</th>
        </tr>
      </thead>
    </table>
  </div>
  <div class="col-lg-3 mb-2">
    <table class="table">
      <thead class="thead-dark">
        <tr>
          <th scope="col" style="text-align: center">Weather NOW</th>
        </tr>
      </thead>
    </table>
  </div>
  <div class="col-lg-1 my-auto">
    <h1 class="display-4 text-center">1</h1>
  </div>
  <div class="col-lg-8"></div>
  <div class="col-lg-3 my-auto" id="customize-script-container"></div>

</div>
© www.soinside.com 2019 - 2024. All rights reserved.