为什么此代码不显示颜色
function doFirst(){
var x= document.getElementById('canvas');
canvas=x.getContext('2d');
var g=canvas.createLinearGradient(0,0,100,100);
g.addColorStop(.0,"blue");
g.addColorStop(1,"red");
canvas.fillstyle=g;
canvas.fillRect(0,0,100,100);
}
window.addEventListener("load", doFirst, false);
答案 0 :(得分:1)
您的代码中有拼写错误,应该有$client = new \GuzzleHttp\Client();
$response = $client->request('GET', $request_url, [
'headers' => ['Accept' => 'application/xml'],
'timeout' => 120
])->getBody()->getContents();
$responseXml = simplexml_load_string($response);
if ($responseXml instanceof \SimpleXMLElement)
{
$key_value = (string)$responseXml->key_name;
}
而不是canvas.fillStyle
。
canvas.fillstyle

function doFirst(){
var x = document.getElementById('canvas');
canvas = x.getContext('2d');
var g = canvas.createLinearGradient(0,0,100,100);
g.addColorStop(.0,"blue");
g.addColorStop(1,"red");
canvas.fillStyle = g;
canvas.fillRect(0,0,100,100);
}
window.addEventListener("load", doFirst, false);

希望这有帮助!
答案 1 :(得分:0)
它奏效了。现在为什么这不起作用: `function doFirst(){ var x = document.getElementById('canvas'); canvas = x.getContext('2d');
canvas.shadowOffsetX = 4;
canvas.shadowOffsetY = 4;
canvas.shadowBlur = 6;
canvas.shadowColor='rgba(0,0,255,.5)';
canvas.font="bold 3px Tahoma";
canvas.textAlign="end";
canvas.fillText("ongwtfbbq",300,100);
} window.addEventListener(“load”,doFirst,false);`