这段HTML5和JS代码运行不出来,哪位大神帮帮忙指点一下,谢谢。
<!doctypehtml><htmllang="en"><head><metacharset="UTF-8"><title>sljfslfjsjf</title><sc...
<!doctype html>
<html lang = "en">
<head>
<meta charset = "UTF-8">
<title>sljfslfjsjf</title>
<script src = "modernizr.js"></script>
<script type = "text/javascript">
window.addEventListener("load", eventWindowLoaded, false);
var Debugger = function(){ };
Debugger.log = function(message) {
try{
console.log(message);
}
catch(exception){
return;
}
}
function eventWindowLoaded(){
canvasApp();
}
function canvasSupport(){
return Modernizr.canvas;
}
function canvasApp(){
if (!canvasSupport()){
return;
}
var theCanvas = document.getElementById("canvasOne");
var context = theCanvas.getContext("2d");
Debugger.log("Drawing Canvas");
function drawScreen(){
context.fillStyle = "red";
context.fillRect(0,0,500,300);
context.fillStyle = "red";
context.font = "20px Sans-Serif";
context.textBaseline = "top";
context.fillText ("hello", 195, 80);
}
drawScreen();
}
</script>
</head>
<body>
<div style = "position: absolute; top: 50px; left: 50px;">
<canvas id = "canvasOne" width ="500" height = "300">
your brow
</canvas>
</div>
</body>
</html> 展开
<html lang = "en">
<head>
<meta charset = "UTF-8">
<title>sljfslfjsjf</title>
<script src = "modernizr.js"></script>
<script type = "text/javascript">
window.addEventListener("load", eventWindowLoaded, false);
var Debugger = function(){ };
Debugger.log = function(message) {
try{
console.log(message);
}
catch(exception){
return;
}
}
function eventWindowLoaded(){
canvasApp();
}
function canvasSupport(){
return Modernizr.canvas;
}
function canvasApp(){
if (!canvasSupport()){
return;
}
var theCanvas = document.getElementById("canvasOne");
var context = theCanvas.getContext("2d");
Debugger.log("Drawing Canvas");
function drawScreen(){
context.fillStyle = "red";
context.fillRect(0,0,500,300);
context.fillStyle = "red";
context.font = "20px Sans-Serif";
context.textBaseline = "top";
context.fillText ("hello", 195, 80);
}
drawScreen();
}
</script>
</head>
<body>
<div style = "position: absolute; top: 50px; left: 50px;">
<canvas id = "canvasOne" width ="500" height = "300">
your brow
</canvas>
</div>
</body>
</html> 展开
1个回答
展开全部
看不到你的 modernizr.js 文件。
仅以你贴出的代码而言,修正后的代码如下,已测试,可在支持 canvas 的浏览器上运行:
<!doctype html>
<html lang = "en">
<head>
<meta charset = "UTF-8">
<title>demo by hutia</title>
<script type = "text/javascript">
window.onload = eventWindowLoaded;
var Debugger = function(){ };
Debugger.log = function(message) {
try {
console.log(message);
} catch(exception){
return;
}
}
function eventWindowLoaded(){
canvasApp();
}
function canvasSupport(){
return true;
}
function canvasApp(){
if (!canvasSupport()){
return;
}
var theCanvas = document.getElementById("canvasOne");
var context = theCanvas.getContext("2d");
Debugger.log("Drawing Canvas");
function drawScreen(){
context.fillStyle = "red";
context.fillRect(0,0,500,300);
context.fillStyle = "red";
context.font = "20px Sans-Serif";
context.textBaseline = "top";
context.fillStyle = "white";
context.fillText ("hello world", 195, 80);
}
drawScreen();
}
</script>
</head>
<body>
<div style="position: absolute; top: 50px; left: 50px;">
<canvas id="canvasOne" width="500" height="300">
your browser do not support canvas
</canvas>
</div>
</body>
</html>
以上,请采纳,请给分。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询