我有一个add方法,每点击一次按钮,添加一个DIV,DIV中包括一个复选框,一个button,一个文本框,但是这几个控件都紧挨在一起,我想把它们格开,怎么做??? 

解决方案 »

  1.   

    用样式可以实现这样的效果吧,<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>
      <META NAME="Generator" CONTENT="EditPlus">
      <META NAME="Author" CONTENT="">
      <META NAME="Keywords" CONTENT="">
      <META NAME="Description" CONTENT="">
      <style type="text/css">
    div {width:100;height:100;background:blue;margin:3;}
      </style>
     </HEAD> <BODY>
      <div id="one"></div>
      <div id="two"></div>
      <div id="three"></div>
     </BODY>
    </HTML>
    新手,不对见谅!
      

  2.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <title>c.html</title>

        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="this is my page">
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <script type="text/javascript">
         function add() {
         var divBox = document.createElement("div");
         var inpEl = document.createElement("input");
         inpEl.type = "text";
         var checkBoxEl = document.createElement("input");
         checkBoxEl.type = "checkbox";
         var btnEl = document.createElement("input");
         btnEl.type = "button";
         btnEl.value = "button";
         divBox.appendChild(inpEl);
         divBox.appendChild(document.createTextNode("    "));
         divBox.appendChild(checkBoxEl);
         //如果用innerHTML创建元素的话可以加&nbsp; el.innerHTML = "<input type='text' />&nbsp;"
         divBox.appendChild(document.createTextNode("    "));
         divBox.appendChild(btnEl);
         document.getElementById("show").appendChild(divBox);
         }
        </script>  </head>
      
      <body>
       <input type="button" value="添加" onclick="add()">
        <div id="show"></div>
      </body>
    </html>
      

  3.   

    innerHTML版:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>c.html</title>
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script type="text/javascript">
    function add() { 
        var divBox = document.createElement("div");
    divBox.innerHTML = "<input type='text'/>&nbsp;&nbsp;<input type='checkbox'/>&nbsp;&nbsp;<input type='button' value='button'/>";
    document.getElementById("show").appendChild(divBox); 
    } </script>
    </head>
    <body>
    <input type="button" value="添加" onclick="add()">
    <div id="show"></div> 
    </body>
    </html>
      

  4.   

    顶楼上的,这种情况使用innerHTML很适合!