jQuery 相当于获取 Canvas 的上下文 [英] jQuery equivalent of getting the context of a Canvas
本文介绍了jQuery 相当于获取 Canvas 的上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下工作代码:
ctx = document.getElementById("canvas").getContext('2d');
有没有办法重写它以使用$
?这样做失败了:
Is there any way to re-write it to use $
? Doing this fails:
ctx = $("#canvas").getContext('2d');
推荐答案
尝试:
$("#canvas")[0].getContext('2d');
jQuery 在数字索引中公开实际的 DOM 元素,您可以在其中执行普通的 JavaScript/DOM 功能.
jQuery exposes the actual DOM element in numeric indexes, where you can perform normal JavaScript/DOM functions.
这篇关于jQuery 相当于获取 Canvas 的上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文