js select 排序

来源:互联网 发布:php实时统计在线人数 编辑:程序博客网 时间:2024/05/16 10:43

<%@ include file="/page/controlHead.jsp" %>
<%@page import="java.util.*,com.anhuily.callcenter.sysmanage.departmanage.*" %>
<%@ page contentType="text/html;charset=gb2312"%>
<SCRIPT src="<%=request.getContextPath()%>/scripts/fileupload.js" type=text/javascript></SCRIPT>
<SCRIPT src="<%=request.getContextPath()%>/scripts/datagrid.js" type=text/javascript></SCRIPT>
<SCRIPT src="<%=request.getContextPath()%>/scripts/ajax.js" type=text/javascript></SCRIPT>
<SCRIPT src="<%=request.getContextPath()%>/scripts/ajax_page.js" type=text/javascript></SCRIPT>
<SCRIPT src="<%=request.getContextPath()%>/scripts/string.js" type=text/javascript></SCRIPT>
<SCRIPT src="<%=request.getContextPath()%>/scripts/eventManager.js" type=text/javascript></SCRIPT>
<SCRIPT src="<%=request.getContextPath()%>/scripts/editor.js" type=text/javascript></SCRIPT>
<SCRIPT src="<%=request.getContextPath()%>/scripts/dataset.js" type=text/javascript></SCRIPT>
<style>body{margin:6px;overflow:auto;}</style>
<script type="text/javascript">
<!--
 function fnUp() {  
     var sel = document.getElementById("departOrderId");  
     for(var i=1; i < sel.length; i++) {//最上面的一个不需要移动,所以直接从i=1开始  
         if(sel.options[i].selected) {  
             if(!sel.options.item(i-1).selected) {//上面的一项没选中,上下交换  
                 var selText = sel.options[i].text;  
                 var selValue = sel.options[i].value;  
  
                 sel.options[i].text = sel.options[i-1].text;  
                 sel.options[i].value = sel.options[i-1].value;  
                 sel.options[i].selected = false;  
  
                 sel.options[i-1].text = selText;  
                 sel.options[i-1].value = selValue;  
                 sel.options[i-1].selected=true;  
             }  
         }  
     }  
 } 
 function fnDown() {  
     var sel = document.getElementById("departOrderId");  
     for(var i=sel.length-2; i >= 0; i--) {//向下移动,最后一个不需要处理,所以直接从倒数第二个开始  
         if(sel.options.item(i).selected) {  
             if(!sel.options.item(i+1).selected) {//下面的Option没选中,上下互换  
                 var selText = sel.options.item(i).text;  
                 var selValue = sel.options.item(i).value;  
  
                 sel.options.item(i).text = sel.options.item(i+1).text;  
                 sel.options.item(i).value = sel.options.item(i+1).value;  
                 sel.options.item(i).selected = false;  
  
                 sel.options.item(i+1).text = selText;  
                 sel.options.item(i+1).value = selValue;  
                 sel.options.item(i+1).selected=true;  
             }  
         }  
     }  
 }
 function obtainData(){
  var v = "";
  var obj = document.getElementById("departOrderId");
  for(var i=0;obj!=null&&i<obj.length;i++){
   v = v+obj.options[i].value+","+(i+1)+"|";
  }
  if(v.length>1){
   v = v.substring(0,v.length-1);
   document.getElementById("displayOrder").value = v;
   document.displayOrderForm.submit();
  }else{
   return;
  }
 }
 
//-->
</script>
<%
 List l = (List)request.getAttribute("list");
%>
<body onLoad="javascript:clear_table();">
<form name="displayOrderForm" action="<%=request.getContextPath()%>/fuwu/fwz/saveFwzDisplayOrder.do">
 <input name="displayOrder" value="" type="hidden" id="displayOrderId"/>
</form>
<TABLE id="sortTable" class="hci" border="1" bordercolordark="#ffffff" bordercolorlight="#eeeeee" cellpadding="3" cellspacing="0">
<title>【部门排序】</title>
<meta:tadd  title="【部门排序】">
<tr ><td name="0;1" width="30.00%" class="hcihead" align="right">&nbsp;</td>
<td name="1;1" width="30.00%" class="hcicontent" align="right">
 <select id="departOrderId" size="<%=l.size() %>">
 <%
  for(int i=0;i<l.size();i++){String[] s =(String[])l.get(i);
   out.print("<option value=/""+s[1]+"/">"+s[0]+"</option>");
  }
 %>
 </select>
</td>
<td name="0;1" width="40.00%" class="hcicontent" align="left">
 <button onClick="fnUp()">上移</button><br>
 <button onClick="fnDown()">下移</button>
</td>
</tr>
<TR class=resbottom>
<TD class=resbottom>&nbsp;</TD>
<TD class=resbottom colspan="2">
 <button onClick="javascript:obtainData();">确认</button>&nbsp;&nbsp;
 <button onClick="javascript:self.close();">取消</button>&nbsp;&nbsp;
</TD>
</TR>
</meta:tadd>
</TABLE>
</body>
<%@ include file="/page/controlTail.jsp" %>