IE和FF2中可以:<form name="abcForm" method="get" id="abcForm">
    <table id="abc" >
    </table>
</form>
<script>
  function createForm(){
    var tbl = document.getElementById("abc");
    var tr = tbl.insertRow(-1);
    var td = tr.insertCell(-1);
    td.innerHTML = " <input type='checkbox' value='true' name='tdname'/>Name"
   
    var tr2 = tbl.insertRow(-1);
    var td2 = tr2.insertCell(-1);
    td2.innerHTML = " <select id=td2 name=tdvalue onchange='submitForm()'> <option value=1>1 </option> <option value=2>2 </option> </select>"  }
  function submitForm(){
      document.abcForm.action = "xxxxxx";
      document.abcForm.submit();
  }
createForm();
</script>可以转到xxxxxx?tdname=true&tdvalue=2

解决方案 »

  1.   

    你的意思是在url里面写死checkbox和select的值么?
    这些值都是动态的哎。
    提交前怎么会知道啊~~~~~
    我想这个不是我要的效果
    thanks anyway
      

  2.   

    '你的意思是在url里面写死checkbox和select的值么? '当然不是,我最后那句‘可以转到xxxxxx?tdname=true&tdvalue=2’是指执行完我贴的那段代码后的运行效果。
      

  3.   

    谢谢
    不过我想知道一下这句话的意图是?“<select id=td2 name=tdvalue onchange='submitForm()'>”
    select也表单中的一项,不是更改了select就要提交的
    可能还有很多东西 都填完了
    按一个按钮再提交
    是否可以指点我的代码关键错在哪里,我好有针对性的解决。
    非常感谢!
      

  4.   


    那只是个DEMO,在select change后触发你的submitForm,你可以自己随意处理,比如在点击某个提交按钮时触发,你的代码本身是没有什么问题的。
      

  5.   

    ........
    可是我的代码在ff下没有效果哎
    我没看出来你改了哪里
    除了post改成get
    这个代码如果在ff下执行,再用ff的页面信息-表单查看的话
    checkbox和select都不在abcForm里
    我想可能就是这个原因导致提交失败
    难道说你的可以?~~~~~
      

  6.   

    你的代碼在我這邊FF2下運行后的DOM結構:<html><head><link href="chrome://firebug/content/highlighter.css" type="text/css" rel="stylesheet"></head><body><form name="abcForm" method="get" id="abcForm">
        <table id="abc">
        <tbody><tr><td> <input value="true" name="tdname" type="checkbox">Name</td></tr><tr><td> <select id="td2" name="tdvalue" onchange="submitForm()"> <option value="1">1 </option> <option value="2">2 </option> </select></td></tr></tbody></table>
    </form>
    <script>
      function createForm(){
        var tbl = document.getElementById("abc");
        var tr = tbl.insertRow(-1);
        var td = tr.insertCell(-1);
        td.innerHTML = " <input type='checkbox' value='true' name='tdname'/>Name"
     
        var tr2 = tbl.insertRow(-1);
        var td2 = tr2.insertCell(-1);
        td2.innerHTML = " <select id=td2 name=tdvalue onchange='submitForm()'> <option value=1>1 </option> <option value=2>2 </option> </select>"  }
      function submitForm(){
          document.abcForm.action = "xxxxxx";
          document.abcForm.submit();
      }
    createForm();
    </script></body></html>
      

  7.   

    可能是你页面上有得元素不标准
    生成的东西应该都是在form中
      

  8.   

    你的创建方法不对。需要tbody这些标记。另外可以使用document.createElement("input")方法
      

  9.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title></title>
     <script>
      function createForm(){
        var tbl = document.getElementById("abc");
        var tr = tbl.insertRow(-1);
        var td = tr.insertCell(-1);
        td.innerHTML = "<input type='checkbox' onclick='cbPjn()' value='true' name='tdname'/>Name"
       
        var tr2 = tbl.insertRow(-1);
        var td2 = tr2.insertCell(-1);
        td2.innerHTML = "<select id=td2> <option value=1>1 </option> <option value=2>2 </option> </select>"  }
      function submitForm(){
       alert(document.abcForm.tdname.value);
    alert(document.abcForm.td2.value);
          //document.abcForm.action = "xxxxxx";
          document.abcForm.submit();
      }
    </script>
    </head>
    <body onload="createForm()">
    <form name="abcForm" method="post" onsubmit="submitForm()">
        <table id="abc" >
        </table>
    <input type="submit" />
    </form></body>
    </html>
      

  10.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title></title>
     <script>
      function createForm(){
        var tbl = document.getElementById("abc");
        var tr = tbl.insertRow(-1);
        var td = tr.insertCell(-1);
        td.innerHTML = "<input type='checkbox' onclick='cbPjn()' value='true' name='tdname'/>Name"
       
        var tr2 = tbl.insertRow(-1);
        var td2 = tr2.insertCell(-1);
        td2.innerHTML = "<select id=td2> <option value=1>1 </option> <option value=2>2 </option> </select>"  }
      function submitForm(){
              alert(document.abcForm.tdname.value);
            alert(document.abcForm.td2.value);
          //document.abcForm.action = "xxxxxx";
          document.abcForm.submit();
      }
    </script>
    </head>
    <body onload="createForm()">
    <form name="abcForm" method="post" onsubmit="submitForm()">
        <table id="abc" >
        </table>
        <input type="submit" />
    </form></body>
    </html>
      

  11.   

    谢谢各位指教
    原来是form要在<body>下,不能再有<table>节点
    我能不能都给分啊。