将元素添加到画布html5

tii*_*in4 5 html5 canvas

可以在HTML5的画布中添加元素吗?

例如:

<canvas id="canvas2" width="650" height="850"> 
    <div class="draggable" class="ui-widget-content" width='100px' height='100px'>
       <textarea class="resizable" rows="2" cols="10" style="color: #FF0707; ">
        Example
       </textarea>
    </div>
</canvas> 
Run Code Online (Sandbox Code Playgroud)

这没有显示任何东西......但是,如果我把那个可拖动的div放在html中的任何其他元素中它可以工作......

我错过了什么?

谢谢.

Min*_*ang 5

您不能像那样将元素添加到画布中。在innerHTML当浏览器不能支持画布的显示<canvas>。您应该在画布旁边或<div>画布上方的图层中添加额外的元素。

<canvas id="canvas2" width="650" height="850"> 

</canvas>
<div style="position: absolute; top: 50px; left: 50px; width: 100px; height: 100px; z-index: 5;" class="draggable" class="ui-widget-content">
   <textarea class="resizable" rows="2" cols="10" style="color: #FF0707; ">
      Example
   </textarea>
</div>
Run Code Online (Sandbox Code Playgroud)

另见:https : //developer.mozilla.org/en/Canvas_tutorial/Basic_usage#Fallback_content