亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用console.log在canvas中進行javascript故障排除

使用console.log在canvas中進行javascript故障排除

滄海一幻覺 2023-06-29 21:06:32
我正在嘗試對一些 javascript 代碼進行故障排除,但我無法在 html 畫布上顯示任何 console.log 信息,以便我可以看到變量的值。有這樣做的基本方法嗎?// JavaScript Document/*jshint esversion: 6 */const canvas = document.getElementById('canvas1');const ctx = canvas.getContext('2d');canvas.width = window.innerWidth;canvas.height = window.innerHeight;console.log("Hello world!");alert("Just executed this code!");canvas {   position: absolute;   top: 0;     left: 0;     width: 100%;     height: 100%;   background: rgba(10,10,153,0.5);}<!doctype html><html><head>    <meta charset="UTF-8">    <meta name="viewport" content="width=device-width, initial-scale=1.0">    <meta http-equiv="X-UA-Compatible" content="ie-edge">    <title>Art01a2020</title>    <link rel="stylesheet" href="style4.css"></head><body>    <canvas id="canvas1"></canvas>    <script type="text/javascript" src="script4.js"></script></body></html>
查看完整描述

1 回答

?
元芳怎么了

TA貢獻1798條經驗 獲得超7個贊

console.log 不會在畫布中記錄內容,它會在資源管理器的開發者控制臺上輸出F12,如果您想調試畫布中的內容,您可以使用fillText 方法在畫布上輸出帶有變量的文本。

例子:

ctx.fillText(some_variable,?screen_x_position,?screen_y_position);


查看完整回答
反對 回復 2023-06-29
  • 1 回答
  • 0 關注
  • 204 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號