js,html,css 讲2张图片 每隔5秒 轮流循环显示。

js,html,css 讲2张图片 每隔5秒 轮流循环显示。,第1张

function changeSrc(nIndex){

var imageList = new Array()

imageList.push("1.jpg")

imageList.push("2.jpg")

var obj = document.getElementById("imagecontain")

obj.src = imageList[nIndex%imageList.length]

}

<div><img id="imagecontain" src="1.jpg" /></div>

<script>

var nIndex = 1

objTimer = window.setInterval(function(){

changeSrc(nIndex)

nIndex++

},1000)

document.getElementById("imagecontain").onmousemove = function(){

clearInterval(objTimer)

}

document.getElementById("imagecontain").onmouseout = function(){

objTimer = window.setInterval(function(){

changeSrc(nIndex)

nIndex++

},1000)

}

</script>

</body>

为什么没人回答,如下代码可以实现

<html>

<head>

<script language="javascript">

function asd(count,url){

document.getElementById("div1").style.display = "block"

var sp = document.getElementById('sp')

sp.innerHTML = count

if(--count > 0)

setTimeout("asd("+count+",'"+url+"')", 1000)

else    

location.href = url

}

</script>

</head>

<body>

<input type="button" onclick="asd(5,'http://www.baidu.com/')" value="点击跳转" />

<div id="div1" style="display:none"><span id="sp"></span>秒后跳转</div>

</body>

</html>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/7331030.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-04
下一篇 2023-04-04

发表评论

登录后才能评论

评论列表(0条)

保存