HTML JavaScript 字符串 转 SQL In

把从Excel粘贴的内容,转为sql语句可以用的格式。

如何使用(以下内容对小白):
新建txt文档,改为html后缀,用记事本打开,粘贴后面的代码进去,再用浏览器打开即可使用。
在这里插入图片描述

<!DOCTYPE html>  
<html lang="en">  
<head>  
    <meta charset="UTF-8">  
    <meta name="viewport" content="width=device-width, initial-scale=1.0">  
    <title>字符串转SQL In</title>  
    <style>  
        .container {  
            display: flex;  
            justify-content: space-between;  
            align-items: flex-start;  
        }  
        .input-area, .output-area {  
            flex: 1;  
            margin: 10px; 
        }  
        .button-area {  
            display: flex;  
            justify-content: center;  
            align-items: center;  
            flex-direction: column;  
        } 
        .input-float {  
            width: 60%;  
            box-sizing: border-box; /* Include padding and border in the element's total width */ 
            float: right;  
        }
        .output-float { 
            width: 60%;  
            box-sizing: border-box; /* Include padding and border in the element's total width */  
            float: left;  
        }
        textarea {  
            width: 60%;  
            box-sizing: border-box; /* Include padding and border in the element's total width */ 
            float: right; 
        }  
        .clear-button {  
            margin-top: 100px; /* Move the button up */  
        } 
        .convert-button {  
            margin-top: 50px; /* Move the button up */  
        } 
    </style>  
</head>  
<body>  
    <div class="container">  
        <div class="input-area">  
            <textarea class="input-float" id="inputText" rows="30" cols="40" style="background-color: azure;font-size: 16px;"></textarea>  
        </div>  
        <div class="button-area">  
            <button onclick="convertToSqlInFormat()" class="convert-button" style="width: 100px;height: 50px;">转换并复制</button>  
            <button onclick="clearInputOutput()" class="clear-button" style="width: 100px;height: 50px;">清除</button>  
        </div> 
        <div class="output-area">  
            <textarea class="output-float" id="outputText" rows="30" cols="40" style="background-color: cornsilk;font-size: 16px;"></textarea>  
        </div>  
    </div>  
    <script>  
        function convertToSqlInFormat() {  
            const input = document.getElementById('inputText').value.trim();  
            const lines = input.split('\n').map(line => line.trim());  
            const sqlValues = lines.map(value => `'${value}'`).join(', \n');  
            const sqlInClause = `IN (${sqlValues})`;  
            document.getElementById('outputText').value = sqlInClause;  
            navigator.clipboard.writeText(sqlInClause);
        }  
        function clearInputOutput() {  
            document.getElementById('inputText').value = '';  
            document.getElementById('outputText').value = '';  
        }
    </script>  
</body>  
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值