日期:2014-05-16  浏览次数:20566 次

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>