javascript 似乎没有创建错误的圆圈,if 语句中的 else 回显。我是否以错误的顺序编写了javascript?我知道它不是 php,因为正确的 div 显示在源代码中。
</style>
<script>
window.onload = function() {
//uetr circle
var canvas = document.getElementById("Canvas");
var context = canvas.getContext("2d");
var centerX = canvas.width / 2;
var centerY = canvas.height / 2;
var radius = 70;
context.beginPath();
context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
context.fillStyle = "#00FF7F";
context.fill();
context.lineWidth = 5;
context.strokeStyle = "black";
context.stroke();
//false circle
var canvas = document.getElementById("Canvas1");
var context = canvas.getContext("2d");
var centerX = canvas.width / 2;
var centerY = canvas.height / 2;
var radius = 70;
context.beginPath();
context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
context.fillStyle = "#B0171F";
context.fill();
context.lineWidth = 5;
context.strokeStyle = "black";
context.stroke();
};
</script>
</head>
<body>
<?php
$visible = true;
if($visible){
echo "<div id='unhidden'><canvas id='Canvas' width='578' height='200'></canvas></div>";
}
else{
echo "<div id='hidden'><canvas id='Canvas1' width='578' height='200'></canvas></div>";
}
?>
</body>
</html>