Javascript 与画布矩形内的彩色正方形颜色不同的文本

Javascript 与画布矩形内的彩色正方形颜色不同的文本,javascript,canvas,Javascript,Canvas,这可能很简单,但是否可以将此绿色文本text 1变为黑色,以便在绿色正方形上方可见 var c=document.getElementById(“canva”); var ctx=c.getContext(“2d”); ctx.font=“20px Arial黑色”; ctx.strokeStyle=‘黑色’; ctx.fillStyle=“绿色”; ctx.fillRect(60,60,80,80); ctx.fillText(“文本2”,120130); ctx.strokeText(“文

这可能很简单,但是否可以将此绿色文本
text 1
变为黑色,以便在绿色正方形上方可见

var c=document.getElementById(“canva”);
var ctx=c.getContext(“2d”);
ctx.font=“20px Arial黑色”;
ctx.strokeStyle=‘黑色’;
ctx.fillStyle=“绿色”;
ctx.fillRect(60,60,80,80);
ctx.fillText(“文本2”,120130);
ctx.strokeText(“文本1”,55,50)

文本1
已经是黑色,但它只是一个笔划,不是填充。在绘制框后但在设置文本之前,通过重置
填充样式
,可以更改填充颜色(文本2的填充颜色):

var c=document.getElementById(“canva”);
var ctx=c.getContext(“2d”);
ctx.font=“20px Arial黑色”;
ctx.strokeStyle=‘黑色’;
ctx.fillStyle=“绿色”;
ctx.fillRect(60,60,80,80);
ctx.fillStyle='黑色';
ctx.fillText(“文本2”,120130);
ctx.strokeText(“文本1”,55,50)

var c=document.getElementById(“canva”);
var ctx=c.getContext(“2d”);
ctx.font=“20px Arial黑色”;
ctx.strokeStyle=‘黑色’;
ctx.fillStyle=“绿色”;
ctx.fillRect(60,60,80,80);
ctx.strokeText(“文本2”,120130);
ctx.strokeText(“文本1”,55,50);