我嘗試使用html2canvas?lib將 div 轉(zhuǎn)換為圖像,但我不斷收到該錯誤html2canvas.min.js:20 Uncaught (in promise) Error: Element is not attached to a Documentat html2canvas.min.js:20at html2canvas.min.js:20at Object.next (html2canvas.min.js:20)at html2canvas.min.js:20at new Promise (<anonymous>)at a (html2canvas.min.js:20)at Vs (html2canvas.min.js:20)at html2canvas.min.js:20at HTMLInputElement.<anonymous> (index4.html:18)at HTMLInputElement.dispatch (jquery-2.2.4.min.js:3)我不明白我的代碼有什么問題,當我在 jsfiddle 上運行代碼時,它不會給我任何錯誤,當我在本地系統(tǒng)上運行它時,它會給我錯誤。代碼<html><head><script src="https://code.jquery.com/jquery-2.2.4.min.js" ></script><script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>?</head><body><div id="phone">45454565756677</div>? ??<div id="out_image"></div>? ???<input type="button" value="Data to Image" id="data_to_image_btn" >??????<script>? ??? ? $(function() {?? ? $("#data_to_image_btn").click(function() {?? ? ? ? html2canvas($("#phone"), {? // no error with : document.getElementById( but nothing is rendered? ? ? ? ? ? onrendered: function(canvas) {? ? ? ? ? ? ? ? console.log('done ... ');? ? ? ? ? ? ? ? $("#out_image").append(canvas);? ? ? ? ? ? }? ? ? ? });? ? });});?</script>??</body></html>
JS 錯誤:元素未附加到文檔
青春有我
2023-07-14 15:04:23