我用document.getElementById(reobj).outerHTML="<select id='member' style='width:100px'>"+option+ "</select>";生成的联动菜单,但是看源码里没有option选项,如何把值取到并提交到PHP页面里去处理呢??谢谢,在线等

解决方案 »

  1.   

    document.getElementById(reobj).outerHTML
    这个在源文件里面是看不到,js这样赋值是在内在里面的。界面上是可以显示的还有,
    你想怎样提交给php页面呢?
    是选择select时提交给php?
      

  2.   

    document.getElementById(reobj).outerHTML="<select id='member' name='member'style='width:100px'>"+option+ "</select>"
    加个name,然后和取text一样处理,就能取到选中的直
    如果要option的所有值,要用js把option的所有值做成字符传,夫给hidden,再取hidden
      

  3.   

    回复一个小泡:生成的是单选菜单,我想选个值后可以POST给main.php
    我再试下楼上说的方法,谢谢
      

  4.   

    “如果要option的所有值,要用js把option的所有值做成字符传,夫给hidden,再取hidden”如何用JS把所有值做成字符串呢?单选的搞定了,现在就差下面的多选了,也是用outerHtml生成的,不过是多选的,谢谢,用数组取不到
      

  5.   

    多选点击的时候不能够,触发事件,给hidden这个方法应该可以
      

  6.   

    <!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>aaaa</title>
    <link href="css/css.css" rel="stylesheet" type="text/css" />
    </head>
    <body onload="cc()"><input type="button" onclick="cc()">
    <select name="sel">
    <option value="a">11</option>
    <option value="b">22</option>
    </select>
    <input type="hidden" name="bbb">
    <script>
    function cc(){
    var a=document.getElementsByName("sel")[0].options
    var c=""
    for(var i=0;i<a.length;i++){
      c=c+a[i].value+","
    }
    alert(c)
    document.getElementsByName("bbb")[0].value=c
    }
    </script>
    </body>
    </html>下个页面取bbb的、值,和text一样,然后分割数组
      

  7.   

    我把我的代码发上来给你们看一下吧,有点说不明白,我从一个部门列表选择后(单选)传给PHP生成部门成员再传回来用outerHtml生成列表(单选),在这同进还把所有成员生成多选列表框,然后在多选列表里把要选取的成员再传给另一个列表框(多选),现在就是要把这个列表框里的值再传给PHP处理,代码如下:包括JS,用DW打开就能看明白我说的意思了
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script language="JavaScript" type="text/javascript">
    var http_request=false;
      function send_request(url,y){//初始化,指定处理函数,发送请求的函数
        dept=y;
    http_request=false;
    //开始初始化XMLHttpRequest对象
    if(window.XMLHttpRequest){//Mozilla浏览器
     http_request=new XMLHttpRequest();
     if(http_request.overrideMimeType){//设置MIME类别
       http_request.overrideMimeType("text/xml");
     }
    }
    else if(window.ActiveXObject){//IE浏览器
     try{
      http_request=new ActiveXObject("Msxml2.XMLHttp");
     }catch(e){
      try{
      http_request=new ActiveXobject("Microsoft.XMLHttp");
      }catch(e){}
     }
        }
    if(!http_request){//异常,创建对象实例失败
     window.alert("创建XMLHttp对象失败!");
     return false;
    }

    http_request.onreadystatechange=processrequest;
    //确定发送请求方式,URL,及是否同步执行下段代码
    content='dept='+encodeURIComponent(dept);
    http_request.open("POST",url,true);
    http_request.setRequestHeader("Content-Length",content.length);
      http_request.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
      http_request.Send(content);
      }
      //处理返回信息的函数
      function processrequest(){
       if(http_request.readyState==4){//判断对象状态
         if(http_request.status==200){//信息已成功返回,开始处理信息
      var option=http_request.responseText;
      document.getElementById(reobj).outerHTML="<select name='member' id='member' style='width:100px'>"+option+ "</select>";
      document.getElementById(reobj2).outerHTML="<select id='left_select' name='left_select' size='15' style='width:100px' >"+option+"</select>";
      //
      //output(option);//document.form1.member.write(option);
      //alert(http_request.responseText);
      
     }
     else{//页面不正常
      alert("您所请求的页面不正常!");
     }
       }
      }
      function getclass(obj,obj1,x){
       var pid=x;
       //document.getElementById(obj).outerHTML="<select id='member' style='width:100px'> <option>loading...</option> </select>";
       send_request('main.php?file=ajaxdata',pid);
       reobj=obj;
       reobj2=obj1;
       //alert(pid);
      }
    function getvalue(x){
    var memberl=x;
    alert(memberl);
    }
    </script>
    <table width="80%" border="0" cellspacing="5" cellpadding="0" align="center">
    <form method="post" action="main.php?mod=work&file=workdispose" name="myform">
      <tr>
        <td width="15%" align="center">工作名称</td>
        <td colspan="3"><input type="text" name="workname"></td>
      </tr>
      <tr>
        <td align="center">发布日期</td>
        <td colspan="3"><input type="text" name="begintime"></td>
      </tr>
      <tr>
        <td align="center">截止日期</td>
        <td colspan="2"><input type="text" name="endtime"></td>
        <td>工作状态
          <input type="text" name="work_estate" /></td>
      </tr>
      <tr>
        <td align="center">关键字</td>
        <td colspan="3"><input name="workkey" type="text" size="50"></td>
      </tr>
      <tr>
        <td align="center">工作描述</td>
        <td colspan="3"><{$editor}></td>
      </tr>
      <tr>
        <td align="center">负责人</td>
        <td><select name="prin" style="width:90px" onchange="if(this.value != 'select')getclass('member','left_select',this.options[this.selectedIndex].value)">
          <option value="select" selected="selected" >请选择部门</option>
          <{foreach key=key item=value from=$dept}>
          <option value="<{$key}>" ><{$key}></option>
          <{/foreach}>
        </select></td>
        <td>部门</td>
        <td><select name="member" id="member" style="width:100px" >
    </select> 成员 </td>
      </tr>
      <tr>
        <td align="center">成员</td>
        <td width="17%"><select id="selectl" name="left_select" size="15" style="width:100px">
          
        </select>    </td>
        <td width="8%">
    <table>
      <tr>
        <td><INPUT language="javascript" name="btn_select_addany" onclick="fun_select_addany(document.myform)" style="COLOR: blue; FONT-FAMILY: Webdings; FONT-SIZE: 12pt; FONT-WEIGHT: normal; HEIGHT: 28px; WIDTH: 27px" title="Add any" type=button value="8"></td>
      </tr>
      <tr>
        <td><INPUT language="javascript" name="btn_select_addall" onclick="fun_select_addall(document.myform)" style="COLOR: blue; FONT-FAMILY: Webdings; FONT-SIZE: 12pt; FONT-WEIGHT: normal; HEIGHT: 28px; WIDTH: 27px" title="Add all" type=button value=: DESIGNTIMESP="17713"></td>
      </tr>
      <tr>
        <td><INPUT language="javascript" name="btn_select_dltany" onclick="fun_select_dltany(document.myform)" style="COLOR: blue; FONT-FAMILY: Webdings; FONT-SIZE: 12pt; FONT-WEIGHT: normal; HEIGHT: 28px; WIDTH: 27px" title ="delete any" type=button value="7"></td>
      </tr>
      <tr>
        <td><INPUT language="javascript" name="btn_select_dltall" onclick="fun_select_dltall(document.myform)" style="COLOR: blue; FONT-FAMILY: Webdings; FONT-SIZE: 12pt; FONT-WEIGHT: normal; HEIGHT: 28px; WIDTH: 27px" title ="delete all" type=button value="9"></td>
      </tr>
    </table> </td>
        <td width="60%"><select id="selmember" name="right_select" size="15" style="width:100px" onfocus="getvalue(myform.right_sesect[index]);" multiple>
        </select></td>
      </tr>
      
     </td>
      </tr>
      <tr>
        <td align="center">&nbsp;</td>
        <td colspan="3"><input type="submit" name="Submit" value="提交"></td>
      </tr>
      </form>
    </table>
    <script language="javascript">
    function fun_select_addany(theform){
        var i; 
        for (i=0;i<theform.left_select.length;i++){
            if (theform.left_select.options[i].selected == true){
               if (theform.left_select.options[i].text !=""){
                  theform.right_select.options[theform.right_select.length]=new Option(theform.left_select.options[i].text);
                  theform.left_select.options[i] =new Option("");
                  }
           } 
        }
        for (i=0;i<theform.left_select.length;i++){
            if (theform.left_select.options[i].text ==""){theform.left_select.options.remove(i); i--;}
        } 
    } function fun_select_addall(theform){
        var i;   
        for (i=0;i<theform.left_select.length;i++){
            if (theform.left_select.options[i].text !=""){
               theform.right_select.options[theform.right_select.length]=new Option(theform.left_select.options[i].text);
               }       
        }
        theform.left_select.length=0;     
    }  function fun_select_dltany(theform){
       var i; 
        for (i=0;i<theform.right_select.length;i++){
            if (theform.right_select.options[i].selected == true){
               if (theform.right_select.options[i].text !=""){
                  theform.left_select.options[theform.left_select.length]=new Option(theform.right_select.options[i].text);
                  theform.right_select.options[i] =new Option("");
                  }
           } 
        }
        for (i=0;i<theform.right_select.length;i++){
            if (theform.right_select.options[i].text ==""){theform.right_select.options.remove(i);i--;}
        } 
    }function fun_select_dltall(theform){
        var i;   
        for (i=0;i<theform.right_select.length;i++){
            if (theform.right_select.options[i].text !=""){
               theform.left_select.options[theform.left_select.length]=new Option(theform.right_select.options[i].text);
               }
        }
        theform.right_select.length=0;            
    }     
    </script>