gpt4 book ai didi

javascript - 在运行时添加的 Internet Explorer 中的 Canvas 元素不起作用

转载 作者:行者123 更新时间:2023-11-29 15:04:19 25 4
gpt4 key购买 nike

我正在尝试在一些 Canvas 元素上绘图,当然,我需要它在 Internet Explorer 中工作。所以我做了一些搜索并使用 explorercanvas 来获得该功能。但我发现,出于某种原因,IE 对初始页面加载后添加的 Canvas 元素不满意。

下面的示例有两个 Canvas 元素,一个存在于页面的 HTML 中,另一个添加到 DOM 就绪。在 Canvas 上绘制的脚本仅适用于脚本运行前存在的元素。

Linky

我尝试使用 IE 调试器找出发生了什么,我发现对于 HTML Canvas ,$(this)[0] 返回一个 DispHTMLGenericElement,但运行时 Canvas 返回一个 DispHTMLUnknownElement。我也用 document.getElementByID() 尝试过,同样的事情发生了。这只是 IE 处理 Canvas 元素的另一个奇怪之处吗?有解决办法吗?

最佳答案

来自 Explorer Canvas 的“说明”文件:

If you have created your canvas element dynamically it will not have the getContext method added to the element. To get it working you need to call initElement on the G_vmlCanvasManager object.

     var el = document.createElement('canvas');
G_vmlCanvasManager.initElement(el);
var ctx = el.getContext('2d');

Thats it. Now you can use the HTML5 spec for Canvas as your reference.

关于javascript - 在运行时添加的 Internet Explorer 中的 Canvas 元素不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5421116/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com