javascript - 网页加载一次怎么 变换里面的微信号一次
高洛峰
高洛峰 2017-04-11 13:06:05
0
1
741

比如我在网页里 放一个微信号 45648 1231 456 然后网页加载一次怎么让 这几个微信号轮换呢?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

membalas semua(1)
PHPzhong
<html>

<head></head>

<body>
  <p id="wechat"></p>
  <script>
  var wechatIds = ['45648', ' 1231', '456'],
    wechatIdsKey = 0;
  if (window.localStorage.getItem('wechatIdsKey') == null) {
    window.localStorage.setItem('wechatIdsKey', 0);
  } else {
    wechatIdsKey = window.localStorage.getItem('wechatIdsKey');
    wechatIdsKey++;
    if (wechatIdsKey >= wechatIds.length) {
      wechatIdsKey = 0;
    }
    window.localStorage.setItem('wechatIdsKey', wechatIdsKey);
  }
  document.getElementById('wechat').innerHTML = wechatIds[wechatIdsKey];
  </script>
</body>

</html>

多个:

<html>

<head></head>

<body>
  <p class="wechat"></p>
  <p class="wechat"></p>
  <p class="wechat"></p>
  <script>
  var wechatIds = ['45648', ' 1231', '456'],
    wechatIdsKey = 0;
  if (window.localStorage.getItem('wechatIdsKey') == null) {
    window.localStorage.setItem('wechatIdsKey', 0);
  } else {
    wechatIdsKey = window.localStorage.getItem('wechatIdsKey');
    wechatIdsKey++;
    if (wechatIdsKey >= wechatIds.length) {
      wechatIdsKey = 0;
    }
    window.localStorage.setItem('wechatIdsKey', wechatIdsKey);
  }
  for (var i = 0, l = document.getElementsByClassName('wechat').length; i < l; i++) {
    document.getElementsByClassName('wechat')[i].innerHTML = wechatIds[wechatIdsKey];
  }
  </script>
</body>

</html>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan