选择我有这个功能清除在Firefox
function smth() {
var container = null;
var newContainer = null;
if (window.getSelection) { // all browsers, except IE before version 9
alert("first if");
var selectionRange = window.getSelection();
if (selectionRange.rangeCount > 0) {
var range = selectionRange.getRangeAt(0);
container = range.commonAncestorContainer;
newContainer = container;
}
}
else {
if (document.selection) { // Internet Explorer
alert("second if");
var textRange = document.selection.createRange();
container = textRange.parentElement();
}
}
if (newContainer) {
return newContainer.nodeName;
}
else {
alert("Container object for the selection is not available!");
}
}
后,现在我做什么,我需要选择我需要明确它做。我尝试了一些没有用的东西,有什么想法?
document.selection.clear()
这没有工作。
谢谢你,它有助于预期例如TinyMCE的编辑器窗口中(iframe中实际上) – Ovi 2011-05-31 12:14:37
将无法工作。您将需要使用:tinymce.activeEditor.selection.collapse(); – Recoil 2013-12-02 06:16:57
“对于有问题的浏览器”不再是这种情况。后面的选项适用于所有浏览器,包括最新版本的IE。 (假设你的意思是IE浏览器“有问题”。) – Porschiey 2014-11-07 16:47:26