search

Home  >  Q&A  >  body text

javascript - The canvas tag created by jade/pug returns null using getContext('2d')

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?

为情所困为情所困2748 days ago635

reply all(1)I'll reply

  • 某草草

    某草草2017-05-19 10:42:25

    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.

    reply
    0
  • Cancelreply