在Firefox中清除选择 [英] Clear a selection in Firefox
本文介绍了在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!");
}
}
现在,在我完成选择后需要做的事情时,我需要清除它.我尝试了几件事没有用,有什么想法吗?
Now after i do what i need to do with the selection i need to clear it. i tried a few things nothing worked, any ideas?
document.selection.clear ()
这没用.
推荐答案
对于有问题的浏览器:
document.selection.empty()
对于其他浏览器:
window.getSelection().removeAllRanges()
请参见 http://help.dottoro.com/ljigixkc.php
这篇关于在Firefox中清除选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文