簡體   English   中英

如何在iframe中獲取字符偏移?

[英]How to get character offset in an iframe?

$(document).ready(function () {
    $('#textEditor').contents().keypress(function (e) {
        if (e.which == 35) {
            alert('# pressed');
            //How to get '#' character offset relative to an iframe
        }
        return true;
    });

#textEditor是我在代碼中使用的iframeID

編輯:以xy坐標偏移,而不是以iframe開頭的字符數偏移

提前致謝。

var selection = window.getSelection();
var range = selection.getRangeAt(0);
console.log(range.getBoundingClientRect()); // left, top, height, width

暫無
暫無

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

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