喜悦国际村 » XML/HTML/CSS/Js » 关于左右内容选择的问题,急?

页: [1]
jcj_juan2004-3-4 10:09 AM
关于左右内容选择的问题,急?

脚本说明:
把如下代码加入<body>区域中
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin

// Compare two options within a list by VALUES

function compareOptionValues(a, b)

{

  // Radix 10: for numeric values

  // Radix 36: for alphanumeric values

  var sA = parseInt( a.value, 36 );  

  var sB = parseInt( b.value, 36 );  

  return sA - sB;

}



// Compare two options within a list by TEXT

function compareOptionText(a, b)

{

  // Radix 10: for numeric values

  // Radix 36: for alphanumeric values

  var sA = parseInt( a.text, 36 );  

  var sB = parseInt( b.text, 36 );  

  return sA - sB;

}



// Dual list move function

function moveDualList( srcList, destList, moveAll )

{

  // Do nothing if nothing is selected

  if (  ( srcList.selectedIndex == -1 ) && ( moveAll == false )   )

  {

    return;

  }



  newDestList = new Array( destList.options.length );



  var len = 0;



  for( len = 0; len < destList.options.length; len++ )

  {

    if ( destList.options[ len ] != null )

    {

      newDestList[ len ] = new Option( destList.options[ len ].text, destList.options[ len ].value, destList.options[ len ].defaultSelected, destList.options[ len ].selected );

    }

  }



  for( var i = 0; i < srcList.options.length; i++ )

  {

    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )

    {

       // Statements to perform if option is selected



       // Incorporate into new list

       newDestList[ len ] = new Option( srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected, srcList.options[i].selected );

       len++;

    }

  }



  // Sort out the new destination list

  newDestList.sort( compareOptionValues );   // BY VALUES

  //newDestList.sort( compareOptionText );   // BY TEXT



  // Populate the destination with the items from the new array

  for ( var j = 0; j < newDestList.length; j++ )

  {

    if ( newDestList[ j ] != null )

    {

      destList.options[ j ] = newDestList[ j ];

    }

  }



  // Erase source list selected elements

  for( var i = srcList.options.length - 1; i >= 0; i-- )

  {

    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )

    {

       // Erase Source

       //srcList.options[i].value = "";

       //srcList.options[i].text  = "";

       srcList.options[i]       = null;

    }

  }



} // End of moveDualList()

//  End -->

</script>
<form ACTION="" METHOD="POST" name="myForm">

<table border="0">

<tr>

  <td>

    <!-- Multiple Select List with 20 rows size and 70 pixels wide -->

    <!-- Using   for SPACING and alignment -->

    <select multiple size="20" style="width:70" name="listLeft">

      <option value="10">      10 </option>

      <option value="20">      20 </option>

      <option value="30">      30 </option>

      <option value="40">      40 </option>

      <option value="50">      50 </option>

      <option value="A" >       A  </option>

      <option value="B" >       B  </option>

      <option value="F" >       F  </option>

      <option value="X" >       X  </option>

    </select>

  </td>

  <td><NOBR>   

    <input type="button" style="width:90" onclick="moveDualList( this.form.listLeft,  this.form.listRight, false )"  

    name="Add     >>"  value="Add       >>">     <BR>



    <NOBR>      

    <input type="button" style="width:90" onclick="moveDualList( this.form.listRight, this.form.listLeft,  false )"  

    name="Add     <<"  value="Add       <<">     <BR>



    <NOBR>      

    <input type="button" style="width:90" onclick="moveDualList( this.form.listLeft,  this.form.listRight, true  )"  

    name="Add All >>"  value="Add All >>">     <BR>



    <NOBR>      

    <input type="button" style="width:90" onclick="moveDualList( this.form.listRight, this.form.listLeft,  true  )"  

    name="Add All <<"  value="Add All <<">     <BR>

    </NOBR>

  </td>

  <td>

    <select multiple size="20" style="width:70" name="listRight">

      <option value="01">       1  </option>

      <option value="02">       2  </option>

      <option value="03">       3  </option>

      <option value="04">       4  </option>

      <option value="05">       5  </option>

      <option value="D" >       D  </option>

      <option value="G" >       G  </option>

      <option value="K" >       K  </option>

      <option value="Z" >       Z  </option>

      <option value="55">           55  </option>

    </select>

  </td>

</tr>

</table>

</form>
问题:如果提交listRight的值时现在只能得到一个值,如何可以一次提交多个值。我尝试过把listRight改为listRight[ ],但这样的话那些功能键便不能用了。请教各位看看如何实现,非常急,谢谢!

星之海洋22004-3-4 12:32 PM
以前有人问过类似的问题,用隐藏域
[url]http://www.phpx.com/happy/showthread.php?s=&threadid=37284[/url]

jcj_juan2004-3-5 06:53 AM
这样写隐藏域对么,这样能得到列表的值么
<input  type=hidden  name=propertys value="javascript:document.form1.listRight.value">

星之海洋22004-3-6 06:37 AM
你总有个提交按钮吧,在按提交时传递过去

jcj_juan2004-3-6 07:26 AM
<input type=hidden name=propertys value="javascript:document.form1.listRight.value">

我是指 javascript:document.form1.listRight.value 这样能取到列表的值么

星之海洋22004-3-7 09:24 AM
当然不可以,你这是把HTML语法和JS语法混在一起了


查看完整版本: 关于左右内容选择的问题,急?


Powered by Discuz! Archiver 6.1.0  © 2001-2006 Comsenz Inc.
Processed in 0.006487 second(s), 2 queries