运行了你的程序不太清楚你要表达什么
这个东西bug一大堆!
1:选项编号自增
2:前2个删除不掉
3:单选多选不知道啥意思
4:下拉列表不知道什么意思
5:后面的选择一嘛意思
6:怎么提交?

解决方案 »

  1.   

    额...真的照用了...真的很多BUG的...
      

  2.   

    嗯 BUG是有 就是那序号的问题
    单选多选不用考虑
    下拉列表就是最多选择多少项的意思,增加一项就下拉列表也多一项
    后面的选择 呵呵 是我CSS调试下 这个没有用
    提交 不用的
    就是添加删除 和下拉列表正常就可以了
      

  3.   


    LZ,我献丑了<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>添加删除项【投票】</title>
    <style type="text/css">
    .optiontxt{width:70px;background:#ccc; display:inline-block;}
    .contenttxt{width:180px; background:#FF0000;display:inline-block;}
    </style>
    <script type="text/javascript">
    function add(num){
    document.getElementById('polloption').innerHTML="";
    for(i=1;i<=num;i++){
    var objchoice=document.createElement("label");
        objchoice.sx=i;
        objchoice.innerHTML="<span class=\"optiontxt\">选项"+i+":</span><span class=\"contenttxt\"><input maxlength=\"50\" name=\"choices\" type=\"text\" /></span><span style=\"cursor: pointer;\" onclick=\"del("+i+")\">删除</span><br>"
        document.getElementById("polloption").appendChild(objchoice);
        var opt=new Option('最多选'+i+'项',i);
        document.getElementById("maxselect").options[i]=opt;
        document.getElementById("maxselect").options[i].selected=true;
    }
    }
    function del(sx){
    var list = document.getElementsByTagName("label");
        for(var n=0,j=1;n<list.length;n++){
            var el = list[n];
            if(el.sx==sx){
            if(n<2){alert("至少需要两个选项!");return false;}
            else{
                el.parentNode.removeChild(el);
                n--;
                document.getElementById("maxselect").options[list.length+1]=null;
                document.getElementById("maxselect").options[list.length].selected=true;
                }
            }
            else{
                el.getElementsByTagName("span")[0].innerHTML = "选项"+(j++)+":";
            }
        }
    }
    </script></head><body>
    <div id="polloption"></div>
    <div><a href="javascript: void(0);" onclick="add(document.getElementById('polloption').getElementsByTagName('input').length+1);">+添加一项</a></div>
    <div>投票方式:<input name="polltype" type="radio" value="" />单选 <input name="polltype" type="radio" value="" />多选
     <select id="maxselect" name="maxselect"><option value="">请选择...</option></select></div>
    <script type="text/javascript">
    add(3);
    </script><span class="optiontxt">选项1:</span><span class="contenttxt"><input type="text" /></span>
    </body>
    </html>
      

  4.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>添加删除项【投票】</title>
    <!--style type="text/css">
    .optiontxt{width:70px;background:#ccc; display:inline-block;}
    .contenttxt{width:180px; background:#FF0000;display:inline-block;}
    </style-->
    <script type="text/javascript">
    function add(){
        var i = document.getElementsByTagName("label").length+1;
        var objchoice=document.createElement("label");
        objchoice.sx=i;
        objchoice.innerHTML="<span class=\"optiontxt\">选项"+i+":</span><span class=\"contenttxt\"><input maxlength=\"50\" name=\"choices\" type=\"text\" /></span><span style=\"cursor: pointer;\" onclick=\"del(this.parentElement.sx)\">删除</span><br>"
        document.getElementById("polloption").appendChild(objchoice);
        resetOpt();
    }
    function del(sx){
        var list = document.getElementsByTagName("label");
        if(list.length<=2){
          alert("至少需要两个选项!");
          return false;
        }
        for(var n=0,j=1;n<list.length;n++){
            var el = list[n];
            if(el.sx==sx){
              el.parentNode.removeChild(el);
              n--;
              document.getElementById("maxselect").options[j]=null;
              document.getElementById("maxselect").options[n+1].selected=true;
            }else{
              el.sx=j;
              el.getElementsByTagName("span")[0].innerHTML = "选项"+(j++)+":";
            }
        }
        resetOpt();
    }
    function resetOpt(){
        var opts = document.getElementById("maxselect").options;
        var l = document.getElementsByTagName("label").length;
        opts.length = 0;
        for(var i=1; i<l+1; i++){
          var opt=new Option('最多选'+i+'项',i);
          document.getElementById("maxselect").options[i]=opt;
        }
        document.getElementById("maxselect").options[l].selected=true;
    }
    </script></head><body>
    <div id="polloption"></div>
    <div><a href="javascript: void(0);" onclick="add();">+添加一项</a></div>
    <div>投票方式:<input name="polltype" type="radio" value="" />单选 <input name="polltype" type="radio" value="" />多选
     <select id="maxselect" name="maxselect"><option value="">请选择...</option></select></div>
    <script type="text/javascript">
    for(var k=1;k<4;k++){add(k);}
    </script>
    </body>
    </html>还有什么BUG的话我不保证..不过比你那个好...
      

  5.   

    完善alert("至少需要两个选项!")这个问题<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>添加删除项【投票】</title>
    <style type="text/css">
    .optiontxt{width:70px;background:#ccc; display:inline-block;}
    .contenttxt{width:180px; background:#FF0000;display:inline-block;}
    </style>
    <script type="text/javascript">
    function add(num){
    document.getElementById('polloption').innerHTML="";
    for(i=1;i<=num;i++){
    var objchoice=document.createElement("label");
        objchoice.sx=i;
        objchoice.innerHTML="<span class=\"optiontxt\">选项"+i+":</span><span class=\"contenttxt\"><input maxlength=\"50\" name=\"choices\" type=\"text\" /></span><span style=\"cursor: pointer;\" onclick=\"del("+i+")\">删除</span><br>"
        document.getElementById("polloption").appendChild(objchoice);
        var opt=new Option('最多选'+i+'项',i);
        document.getElementById("maxselect").options[i]=opt;
        document.getElementById("maxselect").options[i].selected=true;
    }
    }
    function del(sx){
    var list = document.getElementsByTagName("label");
        for(var n=0,j=1;n<list.length;n++){
            var el = list[n];
            if(el.sx==sx){
            if(document.getElementById('polloption').getElementsByTagName('input').length<3){alert("至少需要两个选项!");return false;}
            else{
                el.parentNode.removeChild(el);
                n--;
                document.getElementById("maxselect").options[list.length+1]=null;
                document.getElementById("maxselect").options[list.length].selected=true;
                }
            }
            else{
                el.getElementsByTagName("span")[0].innerHTML = "选项"+(j++)+":";
            }
        }
    }
    </script></head><body>
    <div id="polloption"></div>
    <div><a href="javascript: void(0);" onclick="add(document.getElementById('polloption').getElementsByTagName('input').length+1);">+添加一项</a></div>
    <div>投票方式:<input name="polltype" type="radio" value="" />单选 <input name="polltype" type="radio" value="" />多选
     <select id="maxselect" name="maxselect"><option value="">请选择...</option></select></div>
    <script type="text/javascript">
    add(3);
    </script><span class="optiontxt">选项1:</span><span class="contenttxt"><input type="text" /></span>
    </body>
    </html>