互联网从业者的资讯社区
互联网从业者的资讯社区
下载 App 在 App 中打开
今日热议

可以让 button 按钮获取光标的点的方法

<div class="container">
    <button type="button" class="btn" onclick="insertContentAtCursor('[login]请在此输入登录可见内容[/login]\\\\n')">插入登录可见内容</button>
    <textarea id="message" placeholder="在这里输入内容..." ></textarea>
</div>

&lt;script&gt;
function insertContentAtCursor(content) {
    var textArea = document.getElementById('message');
    var caretPos = textArea.selectionStart;

    textArea.value = textArea.value.substring(0, caretPos) + content + textArea.value.substring(caretPos);
    textArea.setSelectionRange(caretPos + content.length, caretPos + content.length);
}
&lt;&#47;script&gt;
https://zhijieshequ.com/post/zbTEAdRQ
回复 去玩儿改名

未登录无法操作

评论






添加按钮示例



插入标题

全文

https://zhijieshequ.com/comment/iFCEWSWa

插入标题
插入加粗标记


...

全文

https://zhijieshequ.com/comment/D5g5CesV

上滑加载更多

服务条款 隐私政策 Cookie 使用条款

© 2024 知结社区 | Powered by Fresns

弗雷森斯(苏州)科技有限公司

苏ICP备2021027795号-3

增值电信业务经营许可证:苏B2-20210954

广播电视节目制作经营许可证:(苏)字第02601号

不良信息举报: jubao@fresns.cn