为什么这条画布线在Chrome中有颜色,而在Firefox中没有

Why does this canvas line have color in Chrome but not Firefox?

本文关键字:有颜色 而在 Firefox Chrome 布线 为什么      更新时间:2023-09-26

http://jsfiddle.net/28z7mb9r/2/

var canvas = document.getElementsByTagName('canvas')[0];
var ctx = canvas.getContext('2d');
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.strokeStyle = "rgb(0, 0, 255);";
ctx.lineTo(100, 100);
ctx.stroke();

在Chrome中,小提琴显示为适当的蓝色。在Firefox中,它是黑色的。

事实证明,Firefox对格式设置更加严格,在strokeStyle定义中不允许使用分号。

ctx.strokeStyle = "rgb(0, 0, 255)";

以上内容在两种浏览器中都能正常工作。

相关文章: