我正在使用以下代码突出显示 iframe 中的文本,但我无法让它工作
function getSelectedText() {
if (window.getSelection) {;
return window.getSelection().toString();
} else if (document.getSelection) {;
return document.getSelection();
} else if (document.selection) {;
return document.selection.createRange().text;
}
}
$(document).ready(function () {
$("#iframe1").live("mouseup", function () {
selection = getSelectedText();
if (selection.length >= 3) {
$(this).html($(this).html().replace(selection, "<span class='highlight'>" + selection + "</span>"));
}
});
});
});