Javascript 如何使用jquery访问画布?
我无法使用jquery访问画布id 我添加了jQuery库。但当我单击画布id时,无法获得警报 但是javascript工作得很好Javascript 如何使用jquery访问画布?,javascript,jquery,html,html5-canvas,Javascript,Jquery,Html,Html5 Canvas,我无法使用jquery访问画布id 我添加了jQuery库。但当我单击画布id时,无法获得警报 但是javascript工作得很好 <script> $(document).ready(function(){ $('#sq').click(function(){ alert('test'); }); }); </script> <canvas id="example" width="260" heigh
<script>
$(document).ready(function(){
$('#sq').click(function(){
alert('test');
});
});
</script>
<canvas id="example" width="260" height="200">
<h2>Shapes</h2>
<p>A rectangle with a black border. In the background is a pink circle. Partially overlaying the
<a href="http://en.wikipedia.org/wiki/Circle" onfocus="drawCircle();" onblur="drawPicture();">circle</a>.
Partially overlaying the circle is a green
<a href="http://en.wikipedia.org/wiki/Square" onfocus="drawSquare();" onblur="drawPicture();" id="sq">square</a>
and a purple <a href="http://en.wikipedia.org/wiki/Triangle" onfocus="drawTriangle();" onblur="drawPicture();">triangle</a>,
both of which are semi-opaque, so the full circle can be seen underneath.</p>
</canvas>
$(文档).ready(函数(){
$('#sq')。单击(函数(){
警报(“测试”);
});
});
形状
有黑色边框的矩形。背景是一个粉红色的圆圈。部分覆盖
.
部分覆盖圆圈的是绿色
还有一个紫色的,
两者都是半透明的,所以下面可以看到完整的圆圈
您在画布
元素中放置的所有内容都是:它不会在现代浏览器中使用,因此您无法访问它,也无法单击它
在现代浏览器中正确使用画布
是使用其上下文
绘制画布
发件人: