我正在画布上制作绘图板。当使用 jquery 单击输入图像时,我正在尝试更改画布的背景。
这是我的画布和按钮的 html 代码
帆布:
<canvas id="myCanvas" width="640" height="480"></canvas>
点击输入类型图片:
<section id="canvascolor">
<input id="whitecanvas" class="canvasborder" type="image" src="images/whitecanvas.jpg" onClick="Whitecanvas()">
<input id="blackcanvas" class="canvasborder" type="image" src="images/blackcanvas.jpg" onClick="Blackcanvas()">
<input id="yellowcanvas" class="canvasborder" type="image" src="images/yellowcanvas.jpg" onClick="Yellowcanvas()">
<input id="bluecanvas" class="canvasborder" type="image" src="images/bluecanvas.jpg" onClick="Bluecanvas()">
<input id="redcanvas" class="canvasborder" type="image" src="images/redcanvas.jpg" onClick="Redcanvas()">
<input id="greencanvas" class="canvasborder" type="image" src="images/greencanvas.jpg" onClick="Greencanvas()">
</section>
CSS:
canvas{
background-image:url(../images/whitetexturepaper.jpg);
background-repeat:no-repeat;
background-size:cover;
}
我尝试了以下jquery,但它不起作用!:
function Whitecanvas(){
$("#myCanvas").css("background-image","url(images/whitetexturepaper.jpg)");
}