输出没有生成...... [英] The output is not generated...
本文介绍了输出没有生成......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是代码>>>>
Here is the code>>>>
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" media="all" href="css/reset.css" /> <!-- reset css -->
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<style>
body{ background-color: ivory; }
canvas{border:1px solid red;}
</style>
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
function star(ctx, x, y, r, p, m)
{
ctx.save();
ctx.beginPath();
ctx.translate(x, y);
ctx.moveTo(0, 0 - r);
for (var i = 0; i < p; i++)
{
ctx.rotate(Math.PI / p);
ctx.lineTo(0, 0 - (r * m));
ctx.rotate(Math.PI / p);
ctx.lineTo(0, 0 - r);
}
ctx.fill();
ctx.restore();
}
star(ctx, 100, 100, 90, 5, 0.5);
</script>
</head>
<body>
<canvas id="canvas" width=300 height=300></canvas>
</body>
</html>
在输出中我没有得到明星......
In output i didn't get the star...
推荐答案
那是因为没有调用star
函数。您应该在文档就绪事件
中运行。
演示 - [演示]在画布上显示星星 [ ^ ]
That is becausestar
function is not invoked. You should run that indocument ready event
.
Demo - [Demo] Display Star on Canvas[^]
将脚本
元素移至body
,使其成为body
元素的子元素。你会观察到这颗恒星。问题已经解决了。
现在阅读有关使用脚本
元素的内容并考虑一下。
-SA
Move yourscript
element tobody
, make it a child of thebody
element. You will observe the star. The problem is solved.
Now read about usingscript
element and think about it.
—SA
这篇关于输出没有生成......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文