免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
contentEditable
function getDivContent(wrapper){
var textareaText = '';
for (var i = 0; i < wrapper.childNodes.length; i++) {
if (wrapper.childNodes[i].nodeName !== '#text') {
if (wrapper.childNodes[i].innerHTML == '<br>') {
textareaText += wrapper.childNodes[i].innerHTML
} else {
textareaText += wrapper.childNodes[i].innerText.replace(/\n$/,'') + ((i == wrapper.childNodes.length - 1|| wrapper.childNodes[i].innerText=='\n') ? '' : '<br>')
}

} else {
textareaText += wrapper.childNodes[i].nodeValue + ((i == wrapper.childNodes.length - 1 || wrapper.childNodes[i+1].nodeName=='BR') ? '' : '<br>')
}
}
return textareaText
}

  

在光標(biāo)所在位置插入文本

 if (!selection) {
                            selection = getSelection();
                        }
                        if (lastEditRange) {
                            selection.removeAllRanges()
                            selection.addRange(lastEditRange)

                            // 判斷選定對(duì)象范圍是編輯框還是文本節(jié)點(diǎn)
                            if (selection.anchorNode.nodeName != '#text') {
                                if (selection.anchorNode == addLinkFrame.inputWrapper) {
                                    console.log(0)
                                    addLinkFrame.inputWrapper.insertBefore(html, addLinkFrame.inputWrapper.childNodes[selection.anchorOffset])
                                } else if (addLinkFrame.inputWrapper.childNodes.length == 0 || (addLinkFrame.inputWrapper.childNodes.length == 1 && !addLinkFrame.inputWrapper.childNodes[0].innerText)) {
                                    console.log(1)
                                    addLinkFrame.inputWrapper.innerHTML = '';
                                    addLinkFrame.inputWrapper.appendChild(html)
                                } else if (addLinkFrame.inputWrapper.childNodes.length > 0) {
                                    console.log(2)
                                    // 如果文本框的子元素大于0,則表示有其他元素,則按照位置插入表情節(jié)點(diǎn)
                                    for (var i = 0; i < addLinkFrame.inputWrapper.childNodes.length; i++) {
                                        if (addLinkFrame.inputWrapper.childNodes[i] == selection.anchorNode) {
                                            if (selection.anchorOffset == 0) {
                                                addLinkFrame.inputWrapper.childNodes[i].prepend(html)
                                            }
                                        } else {
                                            if (selection.anchorOffset == 0) {
                                                selection.anchorNode.prepend(html)
                                            }
                                        }
                                    }
                                }
                                // else {
                                //     console.log(2)
                                //     // 否則直接插入一個(gè)表情元素
                                //     // $(addLinkFrame.inputWrapper).append(html)
                                //     addLinkFrame.inputWrapper.appendChild(html)
                                // }
                                // 創(chuàng)建新的光標(biāo)對(duì)象
                                var range = document.createRange();
                                // 光標(biāo)對(duì)象的范圍界定為新建的表情節(jié)點(diǎn)
                                range.selectNodeContents(html)
                                // 光標(biāo)位置定位在表情節(jié)點(diǎn)的最大長(zhǎng)度
                                range.setStart(html, html.length)
                                // 使光標(biāo)開始和光標(biāo)結(jié)束重疊
                                range.collapse(true)
                                // 清除選定對(duì)象的所有光標(biāo)對(duì)象
                                selection.removeAllRanges()
                                // 插入新的光標(biāo)對(duì)象
                                selection.addRange(range)
                            } else {
                                console.log(3)
                                // 如果是文本節(jié)點(diǎn)則先獲取光標(biāo)對(duì)象
                                var range = selection.getRangeAt(0)
                                // 獲取光標(biāo)對(duì)象的范圍界定對(duì)象,一般就是textNode對(duì)象
                                var textNode = range.startContainer;
                                // 獲取光標(biāo)位置
                                var rangeStartOffset = range.startOffset;
                                // 文本節(jié)點(diǎn)在光標(biāo)位置處插入新的表情內(nèi)容
                                textNode.insertData(rangeStartOffset, html.innerText)
                                // 光標(biāo)移動(dòng)到到原來(lái)的位置加上新內(nèi)容的長(zhǎng)度
                                range.setStart(textNode, rangeStartOffset + html.length)
                                //光標(biāo)開始和光標(biāo)結(jié)束重疊
                                range.collapse(true)
                                // 清除選定對(duì)象的所有光標(biāo)對(duì)象
                                selection.removeAllRanges()
                                // 插入新的光標(biāo)對(duì)象
                                selection.addRange(range)
                            }
                            // 無(wú)論如何都要記錄最后光標(biāo)對(duì)象
                            lastEditRange = selection.getRangeAt(0)
                        } else {
                            console.log(4)
                            // G.error('請(qǐng)選中你所需要添加光標(biāo)的位置');
                            var allhtml = $(addLinkFrame.inputWrapper).text() + html.innerText;
                            $(addLinkFrame.inputWrapper).text(allhtml)
                        }

 

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
基于HTML5打造的一款別踩白板小游戲
javascript中的NodeType、NodeValue、NodeName實(shí)例測(cè)試
js中的節(jié)點(diǎn)遍歷+類數(shù)組對(duì)象
JavaScript 節(jié)點(diǎn)及層級(jí)操作
JavaScript中Element與Node的區(qū)別,children與childNodes的區(qū)別
深入理解javascript中的動(dòng)態(tài)集合
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服