报错代码:

这个函数运行时

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
function download(){
    var element = $("#demo");    //jquery 获取元素


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



    })
}

 

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

 jQuery配合html2canvas 使用时 报错 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

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄