var canvas = document.getElementById("myCanvas"); if (!canvas.getContext) { return; } var ctx = canvas.getContext("2d"); drawText(); drawHollowText(); function drawText() { ctx.save(); ctx.font = "Bold 40px Arial"; ctx.fillStyle = "#F60"; ctx.fillText("Hello Canvas", 10, 100); ctx.restore(); } function drawHollowText() { ctx.save(); ctx.textAlign = "center"; ctx.font = "Bold 70px Arial"; ctx.strokeStyle = "#F60"; ctx.strokeText("Hello Canvas", 220, 230); ctx.restore(); }
<canvas id="myCanvas" width="440" height="300"> 您的浏览器不支持canvas! </canvas>