<!DOCTYPE html>
<html>
<head>
    <style>
        body {
            background-image: url('map.jpg');
            background-size: cover;
        }
<pre><code>    .btn {
        position: absolute;
        width: 100px;
        height: 100px;
        border-radius: 50%;
        background-color: red;
        color: white;
        text-align: center;
        line-height: 100px;
        cursor: pointer;
    }
&lt;/style&gt;
</code></pre>
</head>
<body>
    <div class="btn" id="btn1" onclick="showCode('Button 1')">Button 1</div>
    <div class="btn" id="btn2" onclick="showCode('Button 2')">Button 2</div>
    <div class="btn" id="btn3" onclick="showCode('Button 3')">Button 3</div>
<pre><code>&lt;script&gt;
    function showCode(title) {
        alert('HTML code: &lt;div&gt;' + title + '&lt;/div&gt;');
    }

    var buttons = document.getElementsByClassName(&quot;btn&quot;);
    for (var i = 0; i &lt; buttons.length; i++) {
        var posX = Math.floor(Math.random() * window.innerWidth);
        var posY = Math.floor(Math.random() * window.innerHeight);
        buttons[i].style.left = posX + &quot;px&quot;;
        buttons[i].style.top = posY + &quot;px&quot;;
    }
&lt;/script&gt;
</code></pre>
</body>
</html>
HTML 代码:随机位置红色圆形按钮,点击显示标题

原文地址: https://www.cveoy.top/t/topic/ph9g 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录