Uncaught TypeError: Cannot read property 'createDocumentFragment' of undefined (using wysiwyg)
Uncaught TypeError: Cannot read property 'createDocumentFragment' of undefined (using wysiwyg)
这是我的 jQuery:
$(".wysiwygtext").on("keyup keypress paste mouseup", function (e, t) {
clearTimeout(timeout);
timeout = setTimeout(function (e, t) {
var element = $(this).html(); //throws 'Uncaught TypeError: Cannot read property 'createDocumentFragment' of undefined'
var value = $(this).val(); //throws 'Uncaught TypeError: Cannot read property 'toLowerCase' of undefined' error
console.log(element);
console.log(value);
}, 2000);
});
.wysiwyg
是应用于某些 div 的 class,像这样(html 是从服务器生成的):
<div class='wysiwygtext' data-guid='" + statementGuid + "' value='" + statementGuid + "'>" + lastbody + "</div>
我只需要在任何文本更改时检索 div (html) 的内容和 div 的值(或 ID),但我得到了这个错误:
Uncaught TypeError: Cannot read property 'createDocumentFragment' of
undefined
感谢您的帮助。
基本上,这是一堆 undefined
参考资料。这就是我最终解决这个问题的方法:
var timeout = null;
$(".wysiwygtext").on("keyup keypress paste mouseup", function (e, t) {
clearTimeout(timeout);
var element = $(this).html();
var value = $(this).val();
timeout = setTimeout(function (e, t) {
console.log(element);
console.log(value);
}, 2000);
});
我在函数外定义了 timeout
,因为 clearTimeout(timeout);
抛出了 timeout is undefined
错误。接下来,我在超时之外定义了 element
和 value
,因为 $(this).html()
和 $(this).val()
没有引用正确的东西。最后,我将 console.log(element)
和 colsole.log(value)
保留在超时内,因此它们将在上述事件之一发生后 2 秒记录。
这是我的 jQuery:
$(".wysiwygtext").on("keyup keypress paste mouseup", function (e, t) {
clearTimeout(timeout);
timeout = setTimeout(function (e, t) {
var element = $(this).html(); //throws 'Uncaught TypeError: Cannot read property 'createDocumentFragment' of undefined'
var value = $(this).val(); //throws 'Uncaught TypeError: Cannot read property 'toLowerCase' of undefined' error
console.log(element);
console.log(value);
}, 2000);
});
.wysiwyg
是应用于某些 div 的 class,像这样(html 是从服务器生成的):
<div class='wysiwygtext' data-guid='" + statementGuid + "' value='" + statementGuid + "'>" + lastbody + "</div>
我只需要在任何文本更改时检索 div (html) 的内容和 div 的值(或 ID),但我得到了这个错误:
Uncaught TypeError: Cannot read property 'createDocumentFragment' of undefined
感谢您的帮助。
基本上,这是一堆 undefined
参考资料。这就是我最终解决这个问题的方法:
var timeout = null;
$(".wysiwygtext").on("keyup keypress paste mouseup", function (e, t) {
clearTimeout(timeout);
var element = $(this).html();
var value = $(this).val();
timeout = setTimeout(function (e, t) {
console.log(element);
console.log(value);
}, 2000);
});
我在函数外定义了 timeout
,因为 clearTimeout(timeout);
抛出了 timeout is undefined
错误。接下来,我在超时之外定义了 element
和 value
,因为 $(this).html()
和 $(this).val()
没有引用正确的东西。最后,我将 console.log(element)
和 colsole.log(value)
保留在超时内,因此它们将在上述事件之一发生后 2 秒记录。