[英]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
是我在代碼中使用的iframe的ID
編輯:以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.