就是这个样的粗爆,手搓一个计算器:带宽计算器

线上运行,可以直接打开:带宽计算器(在线计算器)

       作为程序员,没有合适的工具,就得手搓一个,PC端,移动端均可适用。废话不多说,直接上代码。

HTML:

<div class="calculator"><input id="fileSize" type="number" placeholder="输入文件大小 (MB)"> <input id="time" type="number" placeholder="输入下载时间 (秒)"><button onclick="calculateBandwidth()">计算带宽</button><div id="result" class="result"></div></div>

JS:

function calculateBandwidth() { const fileSize = parseFloat(document.getElementById('fileSize').value); const time = parseFloat(document.getElementById('time').value); if (isNaN(fileSize) || isNaN(time) || fileSize <= 0 || time <= 0) { document.getElementById('result').innerText = '错误:请输入有效的文件大小和时间。'; return; } const bandwidth = (fileSize * 8) / time; // 带宽 = (文件大小 * 8) / 下载时间 document.getElementById('result').innerText = `所需带宽: ${bandwidth.toFixed(2)} Mbps`; }

CSS:

.calculator { width: 100%; background-color: #333; color: white; padding: 20px; border-radius: 10px; box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3); } label { display: block; margin-bottom: 10px; font-size: 16px; } input, select { width: 100%!important; padding: 10px!important; margin-bottom: 20px; color: #000000; border-radius: 5px; border: 1px solid #555; font-size: 16px!important; background-color: #ffffff!important; } button { width: 100%; padding: 10px; background-color: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer; font-size: 16px; } button:hover { background-color: orange; } .result { font-size: 18px; margin-top: 20px; text-align: center; } option { background-color: #ffffff; } p { font-size: 18px; margin-top: 5px!important; }

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容