function addEditButton() {
$(".editButton").remove();
$(".transaction.highlight").removeClass('highlight');
$(this).addClass('highlight');
$(this).append("<input type='button' class='editButton' value='edit' />")
}
$("body").on('click', '.transaction', addEditButton());
使用上述代码时,我收到“未捕获的类型错误:无法读取未定义的属性‘createDocumentFragment’”的错误消息。
我已经尝试搜索一些与此相关的相同问题,现在我假设错误是因为我使用“this”的方式,但我不确定如何解决这个问题。
如果我将所有代码都放在 $("body").on 调用中,代码就可以正常工作,但是当我使用外部 addEditButton() 函数时就不行了。有人可以帮忙吗?
最佳答案
绑定(bind)时不要调用该函数,只需将其作为引用传递即可。
$("body").on('click', '.transaction', addEditButton);
关于javascript - "Uncaught TypeError: Cannot read property ' createDocumentFragment ' of undefined"问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42889602/