jQuery配合html2canvas 使用时 报错 Uncaught (in promise) Provided element is not within a Document

 报错代码:

这个函数运行时

function download(){
    var element = $("#demo");    //jquery 获取元素


    //这里将会报错
    html2canvas(element).then( (canvas)=>{



    })
}

报错:Uncaught (in promise) Provided element is not within a Document

报错原因:    html2canvas(element).then() 中 html2canvas接收的是 一个 js DOM 元素而不是 一个 jQuery DOM对象;

可以尝试 :

可以将代码这样更以解决 报错:

html2canvas(element[0]).then( (canvas)=>{

})

(解决思路: var element = jQuery("#demo")[0]; )

参考地址:https://stackoverflow.com/questions/48290987/uncaught-in-promise-provided-element-is-not-within-a-document

原文地址:https://www.cnblogs.com/taohuaya/p/10768706.html