• 查询HTML标签select中options的值并定位其位置


    查询HTML标签select中options的值并定位其位置!

    JavaScript实现!

     示例:

    <!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0Transitional//EN"> 
    <HTML>
    <HEAD>
     <TITLE>NewDocument</TITLE>
     <META NAME="Author" CONTENT="majianan">
    <SCRIPT>
      varcurrentSel
    =null;
      
    function setButton(obj){    
        
    if(obj.length==0)return;
        currentSel
    =obj;
        
    if(obj.id=="leftSel"){
          document.getElementById(
    "btnLeft").disabled=true;
          document.getElementById(
    "btnRight").disabled=false;        
          reSelect(document.getElementById(
    "rightSel"));      
        }
    else{
          document.getElementById(
    "btnLeft").disabled=false;
          document.getElementById(
    "btnRight").disabled=true;       
          reSelect(document.getElementById(
    "leftSel"));        
        }   
      }
       
    function move(){
         
    if(arguments.length==1){
           moveUp(arguments[
    0]);
         }
    else if(arguments.length==2){
           moveRight(arguments[
    0],arguments[1]);
         }
       }
       
    function moveUp(direction){
         
    if(currentSel==null)
    return;
         
    if(direction){//up
          if(currentSel.selectedIndex>0){ 
            
    for(vari=0;i<currentSel.length;i++){
              
    if(currentSel[i].selected){
                
    var oOption=currentSel.options[i];
                
    var oPrevOption=currentSel.options[i---1];
                currentSel.insertBefore(oOption,oPrevOption);
              }
            }        
          }
         }
    else{//down
          for(var i=currentSel.length-1;i>=0;i--){
            
    if(currentSel[i].selected){
              
    if(i==currentSel.length-1)return;
              
    var oOption=currentSel.options[i];
              
    var oNextOption=currentSel.options[i+1];
              currentSel.insertBefore(oNextOption,oOption);            
            }
          }
         }
       }
      
    function moveRight(src,des){
        
    if(src.selectedIndex==-1){
          alert(
    "Please select first!");
          
    return;
        }
        
    for(var i=0;i<src.length;i++){
          
    if(src[i].selected){
            des.appendChild(src.options[i
    --]);
          }
        }
        setButton(des);
      }
      
      
    function reSelect(obj){
        
    for(var i=0;i<obj.length;i++){
          
    if(obj[i].selected)obj[i].selected=false;
        }
      }

    function chaxun()
    {
    var e=document.getElementById("rightSel");
    var txt=document.getElementById("CHAXUN").value;
    for(var i =0;i<e.options.length;i++)
    {
    if(e.options[i].value == txt))
    {
    e.options[i].selected
    =true;
    }
    else
    e.options[i].selected
    =false;
    }
    }
      
    </SCRIPT>
    </HEAD>
    <BODY>
     <tr>
     <td> <input type="text" id="CHAXUN" size="53" maxlength="1000" value=""></td>
    <td> <input type="submit" id="Submit" value="查询" onclick="chaxun();" title="查询">
    </td>
    </tr>
     <form id="form1">
       <table width="40%"align="center">
         <tr>
           <td>
             <input type="button" value="Up" id="btnUp" onClick="move(true);"style="65"/>
            <br/>
            <input type="button" value="Down" id="btnDowm" onClick="move(false);"style="65"/>        
           </td>
           <td>
             <select multiple id="leftSel" onclick="setButton(this)" ondblclick="document.getElementById('btnRight').click()" style="height:200px;100px;">
              <option value="Java">Java</option>
              <option value="JavaScript">JavaScript</option>
              <option value="C++">C++</option>
              <option value="HTML">HTML</option>
            </select>
          </td>
          <td>
            <input type="button" value=">>" id="btnRight" onClick="move(document.getElementById('leftSel'),document.getElementById('rightSel'));" style="65"/>
            <br/>
            <input type="button" value="<<" id="btnLeft" onClick="move(document.getElementById('rightSel'),document.getElementById('leftSel'));" style="65"/>
            </td>
            <td>
              <select multiple id="rightSel" onclick="setButton(this)" ondblclick="document.getElementById('btnLeft').click()" style="height:200px;100px;">
              <option value="CSS">CSS</option>
              <option value=".Net">.Net</option>
              </select>
            </td>
          </tr>
        </table>
      </form>
    </BODY>
    </HTML>
  • 相关阅读:
    PHP.TP框架下商品项目的优化2-图片优化
    PHP.TP框架下商品项目的优化1-时间插件、鼠标所在行高亮、布局规划页面
    PHP.26-TP框架商城应用实例-后台3-商品修改、删除
    PHP.25-TP框架商城应用实例-后台2-商品列表页-搜索、翻页、排序
    PHP.24-TP框架商城应用实例-后台1-添加商品功能、钩子函数、在线编辑器、过滤XSS、上传图片并生成缩略图
    PHP.23-ThinkPHP框架的三种模型实例化-(D()方法与M()方法的区别)
    PHP.22-Smart模版
    python爬取某站上海租房图片
    Python爬虫入门这一篇就够了
    按PEP8风格自动排版Python代码
  • 原文地址:https://www.cnblogs.com/kingangWang/p/2307595.html
Copyright © 2020-2023  润新知