我想在<div id="lc_div"></div>里通过js输出一个button,应该怎么弄啊??
好像不能用字符串,我刚刚试了试,如果用字符串的话就不能加事件了
所以我这个样弄了,document.write("<input type="button">");可接下来怎么弄啊???

解决方案 »

  1.   

    <html><head><title></title>
    <script language="javascript" type="text/javascript">
    function test(){
        document.getElementById("lc_div").innerHTML="<input type='button' onclick='clickme()' value='clickme'>";
    }
    function clickme(){
    alert('clickme');
    }
    </script>
    </head><body onload="test()"><div id="lc_div"></div>
    </body></html>
      

  2.   


     1楼得效率是最好的 还有一种就是  appendChild  var button =document.createElement("input");
      button.type="button";
      button.value="按钮";
      button.onclick=clickme();
      document.getElementById("lc_div").appendChild(button);