让 Deepseek 写电器电费计算器(html版本)

以下是一个简单的电器电费计算器的HTML和CSS代码:

html 复制代码
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>电器电费计算器</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            line-height: 1.6;
            color: #333;
            max-width: 600px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        
        h1 {
            color: #2c3e50;
            text-align: center;
            margin-bottom: 30px;
        }
        
        .calculator {
            background-color: white;
            border-radius: 8px;
            padding: 25px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: bold;
        }
        
        input[type="number"], 
        input[type="text"] {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
            font-size: 16px;
        }
        
        button {
            background-color: #3498db;
            color: white;
            border: none;
            padding: 12px 20px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            width: 100%;
            transition: background-color 0.3s;
        }
        
        button:hover {
            background-color: #2980b9;
        }
        
        .result {
            margin-top: 20px;
            padding: 15px;
            background-color: #e8f4fc;
            border-radius: 4px;
            display: none;
        }
        
        .result h3 {
            margin-top: 0;
            color: #2c3e50;
        }
        
        .result-value {
            font-size: 24px;
            font-weight: bold;
            color: #e74c3c;
        }
        
        .unit {
            font-size: 16px;
            color: #7f8c8d;
        }
    </style>
</head>
<body>
    <h1>电器电费计算器</h1>
    
    <div class="calculator">
        <div class="form-group">
            <label for="appliance">电器名称</label>
            <input type="text" id="appliance" placeholder="例如: 空调、冰箱等">
        </div>
        
        <div class="form-group">
            <label for="power">电器功率 (瓦)</label>
            <input type="number" id="power" placeholder="例如: 1500">
        </div>
        
        <div class="form-group">
            <label for="hours">每天使用时间 (小时)</label>
            <input type="number" id="hours" placeholder="例如: 8">
        </div>
        
        <div class="form-group">
            <label for="days">每月使用天数</label>
            <input type="number" id="days" placeholder="例如: 30" value="30">
        </div>
        
        <div class="form-group">
            <label for="price">电价 (元/度)</label>
            <input type="number" id="price" step="0.01" placeholder="例如: 0.6" value="0.6">
        </div>
        
        <button onclick="calculate()">计算电费</button>
        
        <div class="result" id="result">
            <h3>计算结果</h3>
            <p><span id="appliance-name"></span>每月消耗约 <span class="result-value" id="consumption">0</span> <span class="unit">度电</span></p>
            <p>每月电费约为 <span class="result-value" id="cost">0</span> <span class="unit">元</span></p>
        </div>
    </div>
    
    <script>
        function calculate() {
            // 获取输入值
            const appliance = document.getElementById('appliance').value || "该电器";
            const power = parseFloat(document.getElementById('power').value);
            const hours = parseFloat(document.getElementById('hours').value);
            const days = parseFloat(document.getElementById('days').value);
            const price = parseFloat(document.getElementById('price').value);
            
            // 计算
            const consumption = (power * hours * days) / 1000; // 转换为度
            const cost = consumption * price;
            
            // 显示结果
            document.getElementById('appliance-name').textContent = appliance;
            document.getElementById('consumption').textContent = consumption.toFixed(2);
            document.getElementById('cost').textContent = cost.toFixed(2);
            
            // 显示结果区域
            document.getElementById('result').style.display = 'block';
        }
    </script>
</body>
</html>

功能说明

这个电费计算器具有以下功能:

  1. 输入电器名称(可选)

  2. 输入电器功率(瓦)

  3. 输入每天使用小时数

  4. 输入每月使用天数(默认30天)

  5. 输入电价(默认0.6元/度)

  6. 点击计算按钮后显示:

    • 每月用电量(度)

    • 每月电费(元)

计算公式

电费计算的基本公式:

每月用电量(度) = 功率(W) × 每天使用小时 × 每月使用天数 ÷ 1000

每月电费(元) = 每月用电量 × 电价

自定义修改

你可以根据需要修改:

  1. CSS样式(颜色、布局等)

  2. 默认值(电价、每月天数等)

  3. 添加更多计算选项(如季节性电价差异)

希望这个计算器对你有帮助!

相关推荐
开开心心就好4 小时前
批量提取PDF中的图片,直接导出原图
前端·javascript·支持向量机·智能手机·pdf·html·启发式算法
Setsuna_F_Seiei7 小时前
前端转型 Agent 开发 05 之 Agent Hooks 与 Checkpointer(让 Agent 从全自动转变人为可掌控)
前端·agent·ai编程
百万蹄蹄向前冲9 小时前
风扇转了一晚上MVP专家团翻车事故
前端·人工智能
默_笙9 小时前
🏛 给 AI 配一间办公室:Harness Engineering 六大模块与它的实现
前端·javascript
Together_CZ10 小时前
DeepSeek-V4.1-Flash:Pushing the Limits of KV Cache Compression——推动 KV 缓存压缩的极限
缓存·llm·compression·kv cache·deepseek·v4.1-flash·推动 kv 缓存压缩的极限
linux_cfan10 小时前
videojs v10 源代码系列解读:14 · 谓词守卫:在运行时安全地调用能力
前端·javascript·音视频
kyriewen10 小时前
我扒了 10,221 条 JD:腾讯技术岗 75% 在要 AI
前端·人工智能·ai编程
郑州光合科技余经理11 小时前
同城外卖小程序开发:下单成功后,后台导出能不能对上用户端状态
开发语言·前端·git·后端·uni-app·php·ai编程
IT_陈寒12 小时前
Vue的响应式让我熬到凌晨三点,原来漏了这个小细节
前端·人工智能·后端
Blanche150012 小时前
利用 RAG 为答疑机器人扩展知识范围
前端