ドロップダウンリストボックスのオプションで並べ替えられたjsは、IE 6とIE 8の互換性のある問題です.

2796 ワード

注:IE 7ではテストされていません.
ページコード:

<table class=table-border align="center" cellspacing="1" cellpadding="1" width="100%">
				<tr>
					<td class="table-bar" align="center">
						    
					</td>
				</tr>
				<tr>
					<td class="table-content" align="center">
						<select name="contractIds" size="15" style="width:100%;" multiple>
							<ww:if test="list.size>0">
								<ww:iterator value="list">
									<option value="<ww:property value='id'/>">
										<ww:property value='contractName'/>
									</option>
								</ww:iterator>
							</ww:if>
						</select>
					</td>
				</tr>
				<tr>
					<td class="table-content" align="center">
						<input type="button" class="button" name="Submit" value="    " onClick="moveUp($('contractIds'));">
						<input type="button" class="button" name="Submit2" value="    " onClick="moveDown($('contractIds'));">
						<input type="button" class="button" name="Submit" value="    " onClick="sort($('contractIds'))">
						<input type="button" class="button" name="Submit" value="    " onClick="doPageBack()">
					</td>
				</tr>
			</table>
jsコード:

<script language="JavaScript">
	/*
	*          
	*object select  
	*/
	function moveUp(object){
		for(var i=0;i<object.options.length;i++){
			var oOption=object.options[i];
			if(oOption.selected){
				if(i>0){
					/*
					var lastIndex = i-1;
					var lastOption=object.options[lastIndex];
					object.insertBefore(oOption,lastOption);
                                        //     IE8        
					*/
					
					//lixf   IE8           
					var lastIndex = i-1;
					var lastOption=object.options[lastIndex];
					var temp = oOption.text;
					var temp2 = oOption.value;
					oOption.text = lastOption.text;
					oOption.value = lastOption.value;
					lastOption.text = temp;
					lastOption.value = temp2;
					oOption.selected = false;
					lastOption.selected = true;
				}
			}
		}
	}