简体   繁体   English

在jQuery中找不到ID为maincanvas的元素?

[英]Could not find element with id maincanvas in jQuery?

This is the error I get 这是我得到的错误

uncaught exception: Could not find element maincanvas

I have included the jQuery file and checked the spelling but error seems to be because of something else 我已包含jQuery文件并检查了拼写,但错误似乎是由于其他原因

<a href="#" id="colorbtn" class="btn">Add Blue</a>           
<canvas id="maincanvas"></canvas>
<script type="text/javascript">
var canvas = $('#maincanvas');
var ctx    = canvas[0].getContext("2d");
var $color      = $('#colorbtn');

Caman('image.jpg','#maincanvas', function(){
this.revert(false);
this.render();
});

$color.on('click', function(e){
e.preventDefault();
Caman('image.jpg','#maincanvas', function(){
this.colorize(60, 105, 218, 10);
this.render();
});
});
</script>

What is causing this error? 是什么导致此错误?

As @ShaunakD says, wait for document-ready. 如@ShaunakD所说,等待文档就绪。

Also, if you're using CamanJS v4 the order of the image & canvas arguments has switched: 另外,如果您使用的是CamanJS v4,则图像和画布参数的顺序已切换:

Caman("#maincanvas", "image.jpg", function() {});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM