javascript - 网页加载一次怎么 变换里面的微信号一次
本文介绍了javascript - 网页加载一次怎么 变换里面的微信号一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
比如我在网页里 放一个微信号 45648 1231 456 然后网页加载一次怎么让 这几个微信号轮换呢?
解决方案
<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>
这篇关于javascript - 网页加载一次怎么 变换里面的微信号一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文