您的位置:首页 > 科技 > IT业 > 引流渠道推广_店铺设计理念_软文拟发布的平台与板块_百度是国企还是央企

引流渠道推广_店铺设计理念_软文拟发布的平台与板块_百度是国企还是央企

2025/5/9 12:05:02 来源:https://blog.csdn.net/weixin_63207763/article/details/142493634  浏览:    关键词:引流渠道推广_店铺设计理念_软文拟发布的平台与板块_百度是国企还是央企
引流渠道推广_店铺设计理念_软文拟发布的平台与板块_百度是国企还是央企

一、网页部分代码

效果图:

代码实现:

<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>工业温湿度采集</title>

    <style>
        body {
            background-color: #f0f0f0;
            background: url('aa.jpg') no-repeat center center fixed;
            font-family: 'Arial', sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }

        .container {
            background-color: #e0d5d4;
            border-radius: 10px;
            padding: 20px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
            text-align: center;
        }

        h1 {
            color: #4a3d3d;
        }

        input[type="text"],
        input[type="button"] {
            width: 80%;
            padding: 10px;
            margin: 10px 0;
            border: none;
            border-radius: 5px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
        }

        input[type="button"] {
            background-color: #8c7a7a;
            color: white;
            cursor: pointer;
            transition: background-color 0.3s;
        }

        input[type="button"]:hover {
            background-color: #c4a6a6;
        }

        .radio-group {
            display: flex;
            justify-content: space-around;
            margin: 10px 0;
        }

        label {
            margin-right: 10px;
        }
    </style>
</head>

<body>

    <div class="container">
        <h1>工业采集控制机制</h1>
        <input type="text" id="temperature" placeholder="温度 (°C)" readonly>
        <input type="text" id="humidity" placeholder="湿度 (%)" readonly>
        <input type="button" value="获取温湿度" οnclick="fetchData()">

        <div class="radio-group">
            <fieldset>
                <legend>LED灯控制</legend>
                <label><input type="radio" name="led" value="on" οnclick="sendControlCommand(name,value)"> 开</label>
                <label><input type="radio" name="led" value="off" οnclick="sendControlCommand(name,value)"> 关</label>
            </fieldset>
        </div>

        <div class="radio-group">
            <fieldset>
                <legend>蜂鸣器控制</legend>
                <label><input type="radio" name="buzzer" value="on" οnclick="sendControlCommand(name,value)"> 开</label>
                <label><input type="radio" name="buzzer" value="off" οnclick="sendControlCommand(name,value)"> 关</label>
            </fieldset>
        </div>
    </div>
    <script>
        function fetchData() {
            // 假设从服务器获取温度和湿度
            var xhr = new XMLHttpRequest(); // 创建XMLHttpRequest对象

            var url = ""; // 请求的URL,这个可以不写

            xhr.open("POST", url, true); // 配置请求:POST方法、URL、异步请求
            xhr.send("get");
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4 && xhr.status === 200) { // 请求完成且成功
                    var x = xhr.responseText.split("/");
                    document.getElementById('temperature').value = x[0];
                    document.getElementById('humidity').value = x[1];
                }
            }
        }
        function sendControlCommand(name,value) {
            var xhr = new XMLHttpRequest(); // 创建XMLHttpRequest对象

            var url = ""; // 请求的URL,这个可以不写

            xhr.open("POST", url, true); // 配置请求:POST方法、URL、异步请求

            if (name == "led") {
                if (value == "on") {
                    xhr.send("set 0 1");
                }
                else if (value == "off") {
                    xhr.send("set 0 0");
                }
            }
            else if(name == "buzzer")
            {
                if(value == "on")
                {
                    xhr.send("set 1 1");
                }
                else if(value == "off")
                {
                    xhr.send("set 1 0");
                }
            }
        }
    </script>
</body>
</html>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com