如何清除< canvas>元件? [英] How do I clear text from the <canvas> element?

查看:142
本文介绍了如何清除< canvas>元件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已在< canvas> 标签中的图像上放置文本(文本是从输入框中获取的)。

I have put text on an image in a <canvas> tag (the text was taken from an input box).

现在,如果我在< canvas> 上放置一个新文本,它会强加在上一个文本上。

Now if I put a new text on the <canvas>, it is imposed on the previous text. How do I clear the existing text on the canvas before putting in the new text?

我已经尝试通过分配 canvas.width <>重置画布, / code>,但文本保持开启。

I have tried resetting the canvas by assigning canvas.width but the text stays on. Any help people?

推荐答案

您需要使用clearRect(x,y,w,h)有关详情,请访问 MDC

You need to use clearRect(x, y, w, h); More details at MDC

这篇关于如何清除&lt; canvas&gt;元件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆