我尝试了以下代码,但firefox4没有显示任何内容。
<script type="text/javascript">
var canvas = document.getElementById('canvas1');
var context = canvas.getContext('2d');
context.strokeStyle = '#990000';
context.strokeRect(20,30,100,50);
alert(context);
</script>
<canvas id="canvas1" width="200px" height="200px">Your browser does not support canvas </canvas>这段代码在body标记中。
发布于 2011-06-11 22:27:05
您必须了解浏览器执行文件的顺序。下面是浏览器读取此代码的方式:
<script type="text/javascript">
var canvas = document.getElementById('canvas1');
var context = canvas.getContext('2d');
context.strokeStyle = '#990000';
context.strokeRect(20,30,100,50);
alert(context);
</script>
<canvas id="canvas1" width="200px" height="200px">Your browser does not support canvas </canvas>canvas主体标记开始
canvas1
nothing.getContext('2d');
alert(nothing)
不显示内部的内容<代码>H121结束主体标记<代码>H222<代码>G223
因此,要使其可见,您只需像这样编辑您的代码:
<!DOCTYPE HTML>
<html>
<head>
<title>Sample by RHNVRM(aka rohan verma)</title>
</head>
<body>
<!--Canvas-->
<canvas id="canvas1" width="200px" height="200px">Your browser does not support canvas </canvas>
<!--Begin Script-->
<script>
var canvas = document.getElementById('canvas1');
var context = canvas.getContext('2d');
context.strokeStyle = '#990000';
context.strokeRect(20,30,100,50);
alert(context);
</script>
</body>
</html>注意:当使用Javascript时,不需要在HTML5中提及它。
发布于 2011-06-11 15:29:20
根据这个搜索,http://www.google.co.uk/search?q=firefox4+canvas Firefox4支持canvas。
发布于 2011-06-11 15:31:00
这对我来说很好用:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>
<canvas id="canvas1" width="200px" height="200px">Your browser does not support canvas </canvas>
<script type="text/javascript">
var canvas = document.getElementById('canvas1');
var context = canvas.getContext('2d');
context.strokeStyle = '#990000';
context.strokeRect(20,30,100,50);
alert(context);
</script>
<body>
</body>
</html>https://stackoverflow.com/questions/6314691
复制相似问题