Javascript 如何在绘制的画布上书写文本?

Javascript 如何在绘制的画布上书写文本?,javascript,html,canvas,Javascript,Html,Canvas,我已在一个功能区上绘制代码: var canvas = document.getElementById('draw-ribbon'); ctx = canvas.getContext("2d"); ctx.fillStyle = 'red'; ctx.beginPath(); ctx.moveTo(0, 0); ctx.lineTo(300, 0); ctx.lineTo(260, 75); ctx.lineTo(300, 150); ctx.lineTo(0, 150); ctx.closeP

我已在一个功能区上绘制代码:

var canvas = document.getElementById('draw-ribbon');
ctx = canvas.getContext("2d");
ctx.fillStyle = 'red';
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(300, 0);
ctx.lineTo(260, 75);
ctx.lineTo(300, 150);
ctx.lineTo(0, 150);
ctx.closePath();
ctx.fill();
得到这个:

在此之后,我尝试了
filltext()
,但没有成功,我想实现以下目标:


可能不起作用,因为文本颜色也是红色

var canvas = document.getElementById('myCanvas');
ctx = canvas.getContext("2d");
ctx.fillStyle = 'red';
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(300, 0);
ctx.lineTo(260, 75);
ctx.lineTo(300, 150);
ctx.lineTo(0, 150);
ctx.closePath();
ctx.fill();
ctx.font="30px Verdana";
ctx.fillStyle = 'white';
ctx.fillText("Text",50,80);