我正在使用以下代码来突出显示 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>"));
}
});
});
});
最佳答案
如果iframe1
是 <iframe>
的 ID , 您需要将它放在您的选择器的引号中。
所以代替:
$(#iframe1).live("mouseup", function () {
//...
你需要:
$('#iframe1').live("mouseup", function () {
//...
关于javascript - jQuery 没有检测到 Iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4694444/