接上一篇,在用canvas实现验证码的时候原先的代码是:
context.fillRect(0, 0, canvas.width, canvas.height);
context.clearRect(0, 0, canvas.width, canvas.height);
思路是先填充目标区域,再清空填充色获得无边框白色画布。
但左右一想这方法实在太蠢,于是改了一下:
context.strokeStyle = "#FFF";
context.strokeRect(0, 0, canvas.width, canvas.height);
即绘制无填充的矩形,再将其笔触设为白色实现无边框。
但在每次点击canvas更换验证码时会出现叠加的现象:
稍微思考便可得知是由于每次给画布填充完内容没有清空,