亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

是否有Internet Explorer批準的selectionStart和selectionEnd

是否有Internet Explorer批準的selectionStart和selectionEnd

慕碼人8056858 2019-11-03 04:04:44
找出在實際瀏覽器中選擇的內容非常簡單:var range = {  start: textbox.selectionStart,  end: textbox.selectionEnd}但是IE和往常一樣無法理解??鐬g覽器的最佳方法是什么?
查看完整描述

3 回答

?
互換的青春

TA貢獻1797條經驗 獲得超6個贊

我當前的解決方案很冗長,并且基于此線程,但是我愿意接受更好的解決方案。


function getSelection(inputBox) {

    if ("selectionStart" in inputBox) {

        return {

            start: inputBox.selectionStart,

            end: inputBox.selectionEnd

        }

    }


    //and now, the blinkered IE way

    var bookmark = document.selection.createRange().getBookmark()

    var selection = inputBox.createTextRange()

    selection.moveToBookmark(bookmark)


    var before = inputBox.createTextRange()

    before.collapse(true)

    before.setEndPoint("EndToStart", selection)


    var beforeLength = before.text.length

    var selLength = selection.text.length


    return {

        start: beforeLength,

        end: beforeLength + selLength

    }

}



查看完整回答
反對 回復 2019-11-04
  • 3 回答
  • 0 關注
  • 323 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號