就是这个样的粗爆,手搓一个计算器:JSON格式化计算器

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

HTML:

html 复制代码
<div class="calculator"><label for="jsonInput">输入 JSON 字符串:</label> <textarea id="jsonInput" rows="10" placeholder="请输入 JSON 字符串"></textarea><button onclick="formatJSON()">格式化</button><div class="result"><div>格式化结果:</div><pre id="jsonOutput" style="color: black; text-align: left;">结果将显示在此处</pre></div></div>

JS:

javascript 复制代码
function formatJSON() {
    const jsonInput = document.getElementById('jsonInput').value.trim();

    if (jsonInput === '') {
        alert('请输入 JSON 字符串');
        return;
    }

    try {
        const jsonObject = JSON.parse(jsonInput);
        const formattedJSON = JSON.stringify(jsonObject, null, 4);
        document.getElementById('jsonOutput').textContent = formattedJSON;
    } catch (e) {
        alert('无效的 JSON 字符串,请检查输入内容');
        document.getElementById('jsonOutput').textContent = '无效的 JSON 字符串';
    }
}

CSS:

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);
}

textarea {
        width: 100%;
    margin-bottom: 10px;
    }

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 {
    margin-top: 20px;
    text-align: center;
}

option {
        background-color: #ffffff;
}


p {
    font-size: 18px;
        margin-top: 5px!important;
}

线上运行,可以直接打开:JSON格式化计算器

相关推荐
paopaokaka_luck7 分钟前
基于springboot3+vue3的车间生产管理系统(Echarts图形化分析、BI报表)
java·前端·spring boot·学习·echarts
程序员鱼皮13 分钟前
3 大 DeepSeek Harness 进阶玩法,招多个大肥鱼帮我干活!
前端·后端·ai编程
KoPa16 分钟前
HeySmart:大模型开源网关基座-请求生命周期与钩子引擎
前端·后端
七牛开发者36 分钟前
Coding Agent 如何跑稳长任务?从上下文管理到运行时状态
前端·javascript·后端
半个落月1 小时前
从 CSR 到 Server Component:吃透 Next.js 16 App Router 路由、布局与 SEO
前端·next.js
七牛开发者1 小时前
拆解 DeepSeek Harness:Profile 与 Bundle 如何装配运行时
前端·javascript·后端
葡萄城技术团队1 小时前
表格智能体系列 · 1:一句话怎么变成一次表格操作
前端
梦曦i1 小时前
Vue-Router 2.4.0 新增可控重定向功能
前端·uni-app
deli0070071 小时前
Markdown 实时预览器:左边写右边看,排版效率翻倍
前端·ai编程
郑州光合科技余经理2 小时前
海外版外卖系统架构:订单怎么流转、权限怎么分
java·开发语言·前端·系统架构·uni-app·php·ai编程