当前位置: 代码迷 >> JavaScript >> js Create canvas,该如何解决
  详细解决方案

js Create canvas,该如何解决

热度:198   发布时间:2012-05-29 12:16:00.0
js Create canvas
我用如下代码创建一个canvas,为什么不对?
JScript code

var link=document.createElement("a");
    link.id=0;
    link.href="#";
    link.onclick=function(id,event){
         switchPicTo(link.id,event);
          return false;};
    document.getElementById("picbar").appendChild(link);
    var linkcanvas=document.createElement("canvas");
    linkcanvas.id="slidepic0";;
    linkcanvas.width='100px';
    linkcanvas.height='90px';
    linkcanvas.style="background:white;margin-top:4px;margin-left:8px;";
    link.appendChild(linkcanvas);


canvas显示不出来,求高手解释!!

------解决方案--------------------
改了几处错误

楼主什么浏览器看的?


标准浏览器才ok

HTML code

<div id="picbar"></div>
<script type="text/javascript">
var link=document.createElement("a");
    link.id=0;
    link.href="#";
    link.onclick=function(id,event){
         switchPicTo(link.id,event);
          return false;};
    document.getElementById("picbar").appendChild(link);
    var linkcanvas=document.createElement("canvas");
    linkcanvas.id="slidepic0";;
    linkcanvas.width='100';
    linkcanvas.height='90';
   // linkcanvas.cssText="background:red;margin-top:4px;margin-left:8px;";
    linkcanvas.style.background="red";
   link.appendChild(linkcanvas);
</script> 
  相关解决方案