javascript - The canvas tag created by jade/pug returns null using getContext('2d')
为情所困
为情所困 2017-05-19 10:40:25
0
1
647

The project uses pug and needs to generate a canvas tag, so the following code is added

canvas(class='work-item_background_canvas')

But after using js to obtain this object, calling getContext('2d') returns null
When the object is printed out, it is <canvas class="work-item_background_canvas">
Please tell me where it comes from Got a problem?

为情所困
为情所困

reply all(1)
某草草

With a template engine like this, you first have to make sure whether it generated what you really wantHTML ELEMENT,模版引擎最终都是生成html的,确定真的有这个dom,那就一定是js运行时的apior if there is something wrong.

The question is not clear to me, but I should check with pug的关系不大,检查一下canvas相关的api whether there is any problem with the call.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template