123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>文本转换器</title>
- </head>
- <body>
- <div>
- <textarea id="input" rows="50" cols="50"></textarea>
- <button id="convert">转换</button>
- <textarea id="output" rows="50" cols="50"></textarea>
- </div>
- <script>
- const input = document.getElementById('input');
- const convertButton = document.getElementById('convert');
- const output = document.getElementById('output');
- function convert() {
- // 获取输入文本域的值
- const inputText = input.value.trim();
- // 对输入文本进行转换
- const convertedText = convertInput(inputText);
- // 将转换后的结果显示在输出文本域中
- output.value = convertedText;
- }
- function convertInput(inputText) {
- const input = JSON.parse(inputText);
- function convertNode(node) {
- if (node.conjunction) {
- return {
- relationship: node.conjunction,
- list: node.children.map(child => convertNode(child))
- };
- } else {
- return {
- key: node.left.field,
- op: node.op,
- value: node.right
- };
- }
- }
- let newVar = {
- relationship: input.conjunction,
- list: input.children.map(child => convertNode(child))
- };
- return JSON.stringify(newVar, null, 4);
- }
- // 绑定转换按钮的点击事件
- convertButton.addEventListener('click', convert);
- </script>
- </body>
- </html>
|