CanvasRenderingContext2D.canvas 属性是 Canvas API 的一部分,是对与给定上下文关联的HTMLCanvasElement对象的只读引用。如果没有 <canvas> 元素与之对应,对象值为null

语法

ctx.canvas;

示例

给出 <canvas> 元素:

<canvas id="canvas"></canvas>

你可以通过CanvasRenderingContext2D调用内部的canvas属性,获取canvas的一个反向引用:

var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
ctx.canvas // HTMLCanvasElement

规范描述

Specification Status Comment
HTML Living Standard
CanvasRenderingContext2D.canvas
Living Standard  

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support YesEdge Full support 12Firefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support

参见

文档标签和贡献者

标签: 
此页面的贡献者: mdnwebdocs-bot, zhangchen, ice-i-snow
最后编辑者: mdnwebdocs-bot,