让 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. 添加更多计算选项(如季节性电价差异)

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

相关推荐
饺子大魔王的男人2 小时前
【Three.js】机器人管线包模拟
javascript·机器人
知否技术2 小时前
知道这10个npm工具包,开发效率提高好几倍!第2个大家都用过!
前端·npm
希希不嘻嘻~傻希希3 小时前
css基础笔记简洁版1
css
希希不嘻嘻~傻希希3 小时前
CSS 字体与文本样式笔记
开发语言·前端·javascript·css·ecmascript
石小石Orz3 小时前
分享10个吊炸天的油猴脚本,2025最新!
前端
爷_4 小时前
Nest.js 最佳实践:异步上下文(Context)实现自动填充
前端·javascript·后端
爱上妖精的尾巴4 小时前
3-19 WPS JS宏调用工作表函数(JS 宏与工作表函数双剑合壁)学习笔记
服务器·前端·javascript·wps·js宏·jsa
草履虫建模4 小时前
Web开发全栈流程 - Spring boot +Vue 前后端分离
java·前端·vue.js·spring boot·阿里云·elementui·mybatis
UI设计和前端开发从业者5 小时前
从UI前端到数字孪生:构建数据驱动的智能生态系统
前端·ui