我是 JQuery 的新手,我正在尝试将一组链接插入带有计时器的 div 框中。这是我见过的代码:
<div id="link"></div>
<script>
var links = [
"Link 01",
"Link 02",
"Link 03",
"Link 04",
"Link 05",
"Link 06",
"Link 07",
"Link 08",
"Link 09",
];
setInterval(function() {
var i = Math.round((Math.random()) * links.length);
if (i == links.length) --i;
$("#link").html(links[i]);
}, 5 * 1000);
</script>
或者像这样更合适:
<div id="apDiv2">
var links = [
<a href="google.com">google.com</a>,
<a href="youtube.com">youtube.com</a>,
<a href="ufl.edu">ufl.edu</a>,
];
</div>
这是我希望链接进入的 div 的样式:
#link {
position:absolute;
width:382px;
height:239px;
z-index:1;
padding: 20px;
left: 173px;
right: 20%;
top: 348px;
background-color: #FFF;
}