
需求是右边编辑sql时,点击左侧常量参数,直接在光标处插入对应的参数,大致实现代码如下:
<input type="text" id="myInput" value="Hello, World!">
<button onclick="insertText()">插入文本</button>
function insertText() {
// 获取 input 元素
const input = document.getElementById('myInput');
// 获取光标当前位置
const start = input.selectionStart;
const end = input.selectionEnd;
// 在光标位置插入文本
const textToInsert = '插入的文本';
input.value = input.value.slice(0, start) + textToInsert + input.value.slice(end);
// 设置新的光标位置
input.selectionStart = start + textToInsert.length;
input.selectionEnd = start + textToInsert.length;
}


![[AutoSar]BSW_Com03 DBC详解 (一)](https://img-blog.csdnimg.cn/direct/418aa8b67bd741d7b04ab4c22a2b5837.png)














![[Linux]文件基础-如何管理文件](https://img-blog.csdnimg.cn/direct/dfc60152711d4fbb86724921f666e4d3.png#pic_center)

