Javascript:使用范围选择器的错误800a025e [英] Javascript: error 800a025e using range selector
问题描述
我最近执行了这些简单的javascript行,即11,只是为了选择div的所有内容
I'm executing these simple rows of javascript in latest ie 11, just to select all content of a div
这是来自ie11开发人员工具的屏幕截图
Here a screenshot from ie11 dev tool
就像您看到的那样,IE改变了我的说法:由于错误800a025e而无法完成操作."
Like you can see, IE alter me saying: "unable to complete the operation due to error 800a025e".
我无法理解问题的性质,根源,而且我所阅读的其他堆栈溢出问题也没有给我明确的答案.
I'm not able to understand the nature, the source, of the problem, and no others stack overflow questions I read give me a clear answer.
这是我的selectText jQuery个人"扩展名的完整代码
This is full code of my selectText jQuery "personal" extension
jQuery.fn.selectText = function(){
var doc = document;
var element = this[0];
// console.log(this, element);
if (typeof element == 'undefined') {
return;
}
if (doc.body.createTextRange) {
var range = document.body.createTextRange();
range.moveToElementText(element);
range.select();
} else if (window.getSelection) {
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
}
};
在这种情况下,元素是
[Object HTMLTableElement]
带有一些mod:
var range = document.body.createTextRange();
var retval = range.moveToElementText(element);
console.log (retval);
range.select();
我可以说您的retval是不确定的. 这段代码在ff上没有问题,因此元素选择器很好. jQuery版本是1.11
I'm able to say you retval is undefined. This code work on ff without problems, so element selector is fine. jQuery version is 1.11
推荐答案
我使用以下技巧解决了此问题:
I resolved using this trick:
我用DIV包装了html表
I wrapped the html table with a DIV
我对DIV使用相同的代码,没有任何更改,而不是仅用于选择表.
I use the same code, as is, with no changes, against the DIV, instead of using for selecting only the table.
正在工作.
可能html表不是IE的可选文本
Probably html table is not a selectable text for IE
这篇关于Javascript:使用范围选择器的错误800a025e的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!