Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript html画布中的换行符_Javascript_Canvas_Line Breaks - Fatal编程技术网

javascript html画布中的换行符

javascript html画布中的换行符,javascript,canvas,line-breaks,Javascript,Canvas,Line Breaks,我制作了一个HTML画布,我想在画布文本中用户名变量后加一个分隔符,但它无法识别我迄今为止尝试过的换行符,例如\n或。这是密码 function drawText() { let startText = "Welcome "+username+"You've answered "+questionCount+" out of 10"; ctx.font = '30px Calibri';//size and type of fo

我制作了一个HTML画布,我想在画布文本中用户名变量后加一个分隔符,但它无法识别我迄今为止尝试过的换行符,例如
\n

。这是密码

function drawText() {
  let startText = "Welcome "+username+"You've answered "+questionCount+" out of 10";
  ctx.font = '30px Calibri';//size and type of font
  ctx.fillStyle = "#f0f0f0";//colour of font
  ctx.textAlign = "center";
  ctx.fillText(startText, 350, 350);
}

window.addEventListener("load", drawText(), false);

您在哪里定义了ctx。。。请完整地输入代码。我想你的问题以前被问过。。。