就是执行左右移动的时候判断移动的值是否在listbox中存在

解决方案 »

  1.   

    当选中listbox1里的1同时按下>>按钮,listbox1的值就变成2,3 那么如何再选中listbox1里的1?
      

  2.   

    listbox我是靠一个下拉列表里的值做条件来绑定数据的~listbox1里的数据是绑定数据库里的数据
      

  3.   

    遍历listbox2.options查值试试看了
    for(var i=0;i<document.listbox2.options.length;i++){
      if (xxxx == document.listbox2.options[i].value){
       alert();return false;
      }
    }
      

  4.   

    <html>
    <head>
    <link rel="stylesheet" href="../../css/xpc.css" type="text/css">
    <meta http-equiv="Content-Type" content="text/html;  charset=UTF-8">
    <title>ecVision XpressCommerce</title>
    <script language="javascript" srccccccc="../../js/CommonJS_SwapOption.js">function moveLeftOrRight(fromObj,toObj)  
    {
    var fromObjOptions=fromObj.options;
    for(var i=0;i<fromObjOptions.length;i++){
    if(fromObjOptions[i].selected){
    toObj.appendChild(fromObjOptions[i]);
    i--;
    }
    }
    resetAutoWidth(fromObj);
    resetAutoWidth(toObj);
    }  function moveLeftOrRightAll(fromObj,toObj)  
    {
    var fromObjOptions=fromObj.options;
    if(fromObjOptions.length>1000) {
    //if(!confirm("Are you sure to move options?")) return false;
    }
    for(var i=0;i<fromObjOptions.length;i++){
    fromObjOptions[0].selected=true;
    toObj.appendChild(fromObjOptions[i]);
    i--;
    }
    resetAutoWidth(fromObj);
    resetAutoWidth(toObj);
    }  function moveUp(selectObj)  

    var theObjOptions=selectObj.options;
    for(var i=1;i<theObjOptions.length;i++) {
    if( theObjOptions[i].selected && !theObjOptions[i-1].selected ) {
    swapOptionProperties(theObjOptions[i],theObjOptions[i-1]);
    }
    }
    selectObj.focus();//For a bug of IE7
    }  
      
    function moveDown(selectObj)  

    var theObjOptions=selectObj.options;
    for(var i=theObjOptions.length-2;i>-1;i--) {
    if( theObjOptions[i].selected && !theObjOptions[i+1].selected ) {
    swapOptionProperties(theObjOptions[i],theObjOptions[i+1]);
    }
    }
    selectObj.focus();//For a bug of IE7
    }  function moveToTop(selectObj){
    var theObjOptions=selectObj.options;
    var oOption=null;
    for(var i=0;i<theObjOptions.length;i++) {
    if( theObjOptions[i].selected && oOption) {
    selectObj.insertBefore(theObjOptions[i],oOption);
    }
    else if(!oOption && !theObjOptions[i].selected) {
    oOption=theObjOptions[i];
    }
    }
    selectObj.focus();//For a bug of IE7
    }function moveToBottom(selectObj){
    var theObjOptions=selectObj.options;
    var oOption=null;
    for(var i=theObjOptions.length-1;i>-1;i--) {
    if( theObjOptions[i].selected ) {
    if(oOption) {
    oOption=selectObj.insertBefore(theObjOptions[i],oOption);
    }
    else oOption=selectObj.appendChild(theObjOptions[i]);
    }
    }
    selectObj.focus();//For a bug of IE7
    }function selectAllOption(selectObj){
    var theObjOptions=selectObj.options;
    for(var i=0;i<theObjOptions.length;i++){
    theObjOptions[i].selected=true;
    }
    }/* private function */
    function swapOptionProperties(option1,option2){
    //option1.swapNode(option2);
    var tempStr=option1.value;
    option1.value=option2.value;
    option2.value=tempStr;
    tempStr=option1.text;
    option1.text=option2.text;
    option2.text=tempStr;
    tempStr=option1.selected;
    option1.selected=option2.selected;
    option2.selected=tempStr;
    }
     
    function resetAutoWidth(obj){
    var tempWidth=obj.style.getExpression("width");
    if(tempWidth!=null) {
    obj.style.width="auto";
    obj.style.setExpression("width",tempWidth);
    obj.style.width=null;
    }
    }
    </script>
    </head>
    <script>
    function saveFun(){
    if(!checkAllNecessaryInputs(document.mainForm)) return false;
    if(document.all.selectedFields.length==0){
    alert("Please select fields.");
    return false;
    }
    selectAllOption(document.all.selectedFields);
    submitXpcForm(document.mainForm);
    }
    </script><body leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="5">
    Sometime we need s<font color="#0000FF">wap options between two multiple-select,</font> we can user the javascript functions in "js/CommonJS_SwapOption.js"<br>   
    Please pay do as the following UI standard:<br>  
    &nbsp;&nbsp;1.There are <font color="#0000FF"> four buttons </font> as follwing for move options right or left .<br>  
    &nbsp;&nbsp;2.The two multiple-select should have dblclick event to move options right or left .<br>  
    &nbsp;&nbsp;3.If need sort order, there will have <font color="#0000FF">four image buttons</font> as follwing  .<br>  
    <hr><form name="mainForm" method="post" action="http://www.ecvision.com"><table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="100%" height="20"></td>
    <td nowrap align="right">
    &nbsp;<input class='button' type='button' value='Edit' disabled name='editButton' disabled >
    &nbsp;<input class='button' type='button' value='Amend' onclick="alert('Amend');" name='amendButton' > 
    &nbsp;<input class='button' type='button' value='Save' onclick="saveFun();" name='saveButton' > 
    </td>
    </tr>
    </table><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr class="listViewThS1">
            <td align="center" nowrap>General</td>
            <td width="100%">&nbsp;</td>
        </tr>
    </table><table width="100%" align="center" border="0" cellspacing="1" cellpadding="0">
      <tr>
        <td align="center" class="attributeLabel">Available Fields  </td> 
        <td width="1%" align="center" class="attributeLabel">&nbsp;</td>
        <td align="center" class="attributeLabel">Selected Fields</td> 
        <td width="1%" align="center" class="attributeLabel">&nbsp;</td>
        </tr>
      <tr>
        <td align="center" class="attributeContent">        
          <select name="barRowAvailableFields" multiple=true size="10" class="ecv_autoSizeDropDown" style="width:200px;"
          onDblClick="moveLeftOrRight(document.all.barRowAvailableFields,document.all.selectedFields)">
          <option value="1">Field 01</option>
          <option value="1">Field 02</option>
          <option value="1">Field 03</option>
          <option value="1">Field 04</option>
          <option value="1">Field 05</option>
          <option value="1">Field 06</option>
          <option value="1">Field 07</option>
          <option value="1">Field 08</option>
          <option value="1">Field 09</option>
          <option value="1">Field 010</option>
          <option value="1">Field 011</option>
          <option value="1">Field 012</option>
          <option value="1">Field 013</option>
          <option value="1">Field 014</option>
          <option value="1">Field 015</option>
          <option value="1">Field 016</option>
          </select>
        </td>
        <td align="center" class="attributeContent">
          <input type="button" class="button" style="width:35px;" value=" >> " onClick="moveLeftOrRightAll(document.all.barRowAvailableFields,document.all.selectedFields)">  
          <br>
          <input type="button" class="button"  style="width:35px;" value="&gt;" onClick="moveLeftOrRight(document.all.barRowAvailableFields,document.all.selectedFields)">
          <br>
          <input type="button" class="button"  style="width:35px;" value="&lt;" onClick="moveLeftOrRight(document.all.selectedFields,document.all.barRowAvailableFields)">
          <br>
          <input type="button" class="button"  style="width:35px;" value=" &lt;&lt; " onClick="moveLeftOrRightAll(document.all.selectedFields,document.all.barRowAvailableFields)">
        </td>
        <td align="center" class="attributeContent">
          <select name="selectedFields" multiple=true size="10" class="ecv_autoSizeDropDown" style="width:200px;" onDblClick="moveLeftOrRight(this,document.all.barRowAvailableFields)" >
          </select>
        </td>
        <td width="5%" class="attributeContent" align="center" >
          <img src="../../img/upTop.gif"   onClick="moveToTop(document.all.selectedFields)" style="cursor:hand;">
          <br><br>
          <img src="../../img/up.gif" onClick="moveUp(document.all.selectedFields)" style="cursor:hand;">
          <br><br>
          <img src="../../img/down.gif" onClick="moveDown(document.all.selectedFields)" style="cursor:hand;"> 
          <br><br>
          <img src="../../img/downBottom.gif" onClick=" moveToBottom(document.all.selectedFields)" style="cursor:hand;"> </td>
      </tr>
    </table></form>
    </body>