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