Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery HTML5';画布:$(文档).ready(函数()-未就绪_Jquery_Html - Fatal编程技术网

Jquery HTML5';画布:$(文档).ready(函数()-未就绪

Jquery HTML5';画布:$(文档).ready(函数()-未就绪,jquery,html,Jquery,Html,我正试着用下面的代码在画布上画画。 alert()返回未定义。 看起来文档已经准备好了,但画布还没有准备好 <!DOCTYPE HTML> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <script type="text/javascript" src="js/jq

我正试着用下面的代码在画布上画画。 alert()返回未定义。 看起来文档已经准备好了,但画布还没有准备好

<!DOCTYPE HTML>
<html lang="en">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <script type="text/javascript" src="js/jquery.js"></script>
        <script type="text/javascript" src="js/myscript.js"></script>
        <link type="text/css" rel="stylesheet" href="css/normalize.css" media="screen" />

        <title></title>
    </head>
    <body>
        <canvas id="space" width="1500" height="1500"></canvas>
    </body>
</html>

嗯,jQuery对象中没有id属性。这就是它未定义的原因

alert($('#space').get(0).id); 
alert($('#space').attr("id")); 
您需要为画布运行DOM

dbCanvas = $('#space').get(0);
context = dbCanvas.getContext('2d');

或者
$('#space').attr('id')
或者
$('#space').prop('id')
dbCanvas=document.getElementById('space');
。这里不需要jQuery。
dbCanvas = $('#space').get(0);
context = dbCanvas.getContext('2d');