无法定位 Canvas 的子元素

Unable to target child element of Canvas

这是我的代码

    javascript: (function() {
    var canvas = document.getElementById("app-view").children[1];
    var img = canvas.toDataURL("image/png");
    window.open(img);
    })();

and here is the app element where I wish to target the second canvas element "children1" 但由于某种原因它不起作用,并且总是卡在第一个元素上。非常感谢解决方案,提前致谢!

在图片中,它始终以黄色显示的第一个 canvas 为目标,但我需要显示为蓝色的那个。您可以通过将脚本保存为浏览器中的书签来测试代码。

这对我有用:

document.getElementById('app-view').childNodes[1]

一直没弄明白为什么toDataURL获取到左边canvas的数据,但是如果想保存canvas,可以用

隔离
var can = document.getElementById("app-view").children[1];
jQuery("body > *").remove();
jQuery("body").append(can) ;

然后现在您可以右键单击并保存 canvas