簡體   English   中英

Javascript-在textarea中的光標位置插入圖片標簽

[英]Javascript - insert image tag at the position of the cursor in the textarea

我知道有幾篇標題相似的文章,但它們似乎並沒有提到相同的問題。 我試圖通過與textearea同一頁面上的按鈕實例化的彈出窗口,將圖像標簽放置在特定文本區域內的光標位置。

目前,我只是將image標簽附加到textarea中內容的末尾,如下所示:

window.opener.document.getElementById('textarea_id').value += '<img .... />';

我在這里找到了一篇文章: 如何在tinymce中的光標位置插入圖像 ,但是顯然,這是指tinymce,它具有一些內置函數。

有什么想法嗎?

您可以使用selectionStart進一步了解它, 網址為: https : //developer.mozilla.org/en-US/docs/DOM/HTMLTextAreaElement

window.opener.document.getElementById('textarea_id').selectionStart

另請參閱文本區域中插入符號的位置(從頭開始的字符)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM