简体   繁体   English

我想刷新我的 html 页面上可用的所有 div,即按标签,我有 2 个代码如何 imerge

[英]i want to refresh my all div available on my html page i.e by tag and i have 2 codes how can imerge

these are my 2 codes which i want to merge on each other and i want to refresh all of the div present on my page and founded that its easy method is to refresh it by tag name only but not getting how to do that my codes are ----->>>这些是我的 2 个代码,我想将它们合并在一起,我想刷新页面上存在的所有 div,并发现它的简单方法是仅通过标签名称刷新它,但不知道如何做到这一点我的代码是----->>>

my html--->我的html--->

<div class="class">
<h1>hi</h1>
</div>

<div class="class2">
<h1>hello</h1>
</div>

code for colouring all my div by tag name ----通过标签名称为我的所有 div 着色的代码----

var x = document.getElementsByTagName("DIV");
document.write(x);
for (i = 0; i < x.length; i++) {
    x[i].style.backgroundColor = "red";
  }

code for ->>>autorefresh single div by it's id in each second------ ->>> 每秒自动刷新单个 div 的代码------

    var intervalID = setInterval(function(){
   $("div").each(function(){
      $(this).load(this.href);
   })
}, 1000);

try to refresh by id or class of div and set the same id to both div尝试通过 id 或 div 的 class 刷新并将相同的 id 设置为两个 div

var d = document.getElementsByClassName("sameclass");
var intervalID = setInterval(function(){ 
  (d).load(this.href);
}, 1000);

this might work这可能有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM