You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何给随机展示的图片添加跳转链接,求完整修复后的可运行代码

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>随机图片跳转</title>
</head>
<body>
<button onclick="getRandomImage()">Show Image</button>
<div class="container">
    <span id="result" align="center"></span>  
</div>

<script>
function getRandomImage() {  
    var randomImage = [
        {src: "frames/1.png", href: "test1.html"},
        {src: "frames/2.png", href: "test2.html"},
        {src: "frames/3.png", href: "test3.html"},
        {src: "frames/4.png", href: "test4.html"},
        {src: "frames/5.png", href: "test5.html"},
        {src: "frames/6.png", href: "test6.html"},
        {src: "frames/7.png", href: "test7.html"},
        {src: "frames/8.png", href: "test8.html"},
        {src: "frames/9.png", href: "test9.html"},
        {src: "frames/10.png", href: "test10.html"}
    ];  

    document.getElementById("result").innerHTML = '';
    for (let i=0; i< 1; i++) {  
        var number = Math.floor(Math.random()*randomImage.length);  
        document.getElementById("result").innerHTML += '<a href="' + randomImage[number].href + '"><img src="'+ randomImage[number].src +'" style="width:450px" alt="随机图片" /></a>';  
    }  
}
</script>
</body>
</html>

内容的提问来源于stack exchange,提问作者JockStrap

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 05:54:03