JS操作select相关方法:新增 修改 删除 选中 清空 判断存在 等
1.判断select选项中 是否存在Value="paraValue"的Item
2.向select选项中 加入一个Item
3.从select选项中 删除一个Item
4.修改select选项中 value="paraValue"的text为"paraText"
5.设置select中text="paraText"的第一个Item为选中
6.设置select中value="paraValue"的Item为选中
7.得到select的当前选中项的value
8.得到select的当前选中项的text
9.得到select的当前选中项的Index
10.清空select的项
-------------------------------------------
//1.判断select选项中 是否存在Value="paraValue"的Item
function jsSelectIsExitItem(objSelect,objItemValue)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
var isExit = false;
for(var i=0;i<objSelect.options.length;i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(objSelect.options[i].value == objItemValue)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
isExit = true;
break;
}
}
return isExit;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//2.向select选项中 加入一个Item
function jsAddItemToSelect(objSelect,objItemText,objItemValue)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
//判断是否存在
if(jsSelectIsExitItem(objSelect,objItemValue))
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
alert("该Item的Value值已经存在");
}
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
var varItem = new Option(objItemText,objItemValue);
// objSelect.options[objSelect.options.length] = varItem;
objSelect.options.add(varItem);
alert("成功加入");
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//3.从select选项中 删除一个Item
function jsRemoveItemFromSelect(objSelect,objItemValue)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
//判断是否存在
if(jsSelectIsExitItem(objSelect,objItemValue))
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for(var i=0;i<objSelect.options.length;i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(objSelect.options[i].value == objItemValue)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
objSelect.options.remove(i);
break;
}
}
alert("成功删除");
}
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
alert("该select中 不存在该项");
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//4.修改select选项中 value="paraValue"的text为"paraText"
function jsUpdateItemToSelect(objSelect,objItemText,objItemValue)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
//判断是否存在
if(jsSelectIsExitItem(objSelect,objItemValue))
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for(var i=0;i<objSelect.options.length;i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(objSelect.options[i].value == objItemValue)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
objSelect.options[i].text = objItemText;
break;
}
}
alert("成功修改");
}
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
alert("该select中 不存在该项");
}
}
//5.设置select中text="paraText"的第一个Item为选中
function jsSelectItemByValue(objSelect,objItemText)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
//判断是否存在
var isExit = false;
for(var i=0;i<objSelect.options.length;i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(objSelect.options[i].text == objItemText)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
objSelect.options[i].selected = true;
isExit = true;
break;
}
}
//Show出结果
if(isExit)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
alert("成功选中");
}
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
alert("该select中 不存在该项");
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//6.设置select中value="paraValue"的Item为选中
//document.all.objSelect.value = objItemValue;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//7.得到select的当前选中项的value
//var currSelectValue = document.all.objSelect.value;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//8.得到select的当前选中项的text
//var currSelectText = document.all.objSelect.options[document.all.objSelect.selectedIndex].text;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//9.得到select的当前选中项的Index
//var currSelectIndex = document.all.objSelect.selectedIndex;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//10.清空select的项
// document.all.objSelect.options.length = 0;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
窗口最大化
<body onload="window.resizeTo(window.screen.width - 4,window.screen.height-50);window.moveTo(-4,-4)">
禁止右键
document.oncontextmenu = function() { return false;}
禁止保存 <noscript><iframe src="*.htm"></iframe></noscript>
禁止选取<body oncontextmenu="return false" ondragstart="return false" onselectstart ="return false"
onselect="document.selection.empty)" oncopy="document.selection.empty)" onbeforecopy=
"return false"onmouseup="document.selection.empty()>
禁止粘贴<input type=text onpaste="return false">
根据宽度换行 style="word-break:break-all"
//消除图像工具栏
[/html]
<IMG SRC="mypicture.jpg" HEIGHT="100px" WIDTH="100px" GALLERYIMG="false">
or
<head>
<meta http-equiv="imagetoolbar" content="no">
</head>
[/html]
//取得控件得绝对位置(1)
<script language="javascript"> <br />
function getoffset(e) <br />
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{ <br />
var t=e.offsetTop; <br />
var l=e.offsetLeft; <br />
while(e=e.offsetParent) <br />
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{ <br />
t+=e.offsetTop; <br />
l+=e.offsetLeft; <br />
} <br />
var rec = new Array(1); <br />
rec[0] = t; <br />
rec[1] = l; <br />
return rec <br />
} <br />
</script> <br />
[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
//获得控件的绝对位置(2)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
oRect = obj.getBoundingClientRect();
oRect.left
oRect.
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//下载文件
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
function DownURL(strRemoteURL,strLocalURL)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
var xmlHTTP=new ActiveXObject("Microsoft.XMLHTTP");
xmlHTTP.open("Get",strRemoteURL,false);
xmlHTTP.send();
var adodbStream=new ActiveXObject("ADODB.Stream");
adodbStream.Type=1;//1=adTypeBinary
adodbStream.Open();
adodbStream.write(xmlHTTP.responseBody);
adodbStream.SaveToFile(strLocalURL,2);
adodbStream.Close();
adodbStream=null;
xmlHTTP=null;
}
catch(e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
window.confirm("下载URL出错!");
}
//window.confirm("下载完成.");
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//检验连接是否有效
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
function getXML(URL)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
var xmlhttp = new ActiveXObject("microsoft.xmlhttp");
xmlhttp.Open("GET",URL, false);
try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
xmlhttp.Send();
}
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
catch(e)
{}
finally
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
var result = xmlhttp.responseText;
if(result)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(xmlhttp.Status==200)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return(true);
}
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return(false);
}
}
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return(false);
}
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//检查网页是否存在
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
function CheckURL(URL)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.Open("GET",URL, false);
try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
xmlhttp.Send();
var result = xmlhttp.status;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
catch(e)
{return(false); }
if(result==200)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return true;
}
xmlhttp = null;
return false;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
1 父子页面的值传递
两种方式:
1)在父页面可以通过pagename操作子页面。
pagename = window.open('page ','name','width,height'); pagename.focus();
在子页面可以通过parents.Label.innerText = '"value"'
2)通过模态对话框返回值。当执行模态对话框时,父页面将停止操作。
在父页面
var result = showModalDialog(url,window,"dialogWidth:"+width+"px;dialogHeight:"+height+"px;help:no;scroll:no;status:no");
alert(result)
在子页面
<script language='javascript'>
window.returnValue = 'True';
window.close()
</script>
3) 通过vArguments将父窗体的值传递到子窗体
<script>
var obj = new Object();
obj.name="51js";
window.showModalDialog ("modal.htm",obj,"dialogWidth=200px;dialogHeight=100px");
</script>
modal.htm
<script>
var obj = window.dialogArguments
alert("您传递的参数为:" + obj.name)
</script>
4) 子窗体使父窗体刷新
opener.window.location.reload();
5) 避免提交时弹出另一个页面
<head>标签里加入<base target="_self">
6) 避免模式窗体不刷新
Response.Expires = -1
Response.ExpiresAbsolute = Now() - 1
Response.cachecontrol = "no-cache"
2 将javascript值赋给session
新建一个框架,不让他显示出来。在页面里
document.all('djTmp').src="djTmp.aspx?name=RoleName&value=" + document.all('cboRole').value
在框架网页里
Dim strName As String = Request.QueryString("name")
Dim strValue As String = Request.QueryString("value")
Session(strName) = strValue
3 服务器控件取js值。
新建一隐藏控件。将其设为服务器端运行,这样通过脚本和服务器都可以访问。
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
参考:http://neozhu.cnblogs.com/archive/2005/07/28/201838.aspx
http://www.phpx.com/happy/showthread.php?threadid=101722&goto=nextnewest
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//==========================================================================
//
// 代码描述:将某个datagrid中模板的中checkbox置为相反状态
//
// 传入参数:Form --- 当前页面ID 例: xt_function_m
// CheckBox --- 被选择的字符 例: 'CheckBoxSelect'
//
// 返回参数:无
//
//
//==========================================================================
function SelectTitleAll(Form, CheckBox)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
var i
var intLength = Form.elements.length
for (i = 0; i < intLength; i ++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
var strType = Form.elements[i].type
var strName = Form.elements[i].name
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if (strType == 'checkbox' && strName.lastIndexOf(CheckBox) == strName.length - CheckBox.length)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Form.elements[i].checked = !Form.elements[i].checked;
}
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//==========================================================================
//
// 代码描述:将表单中所有的checkbox都设置为打勾状态
//
// 传入参数:Form --- 当前页面ID 例: xt_function_m
// CheckBox --- 被选择的字符 例: 'CheckBoxSelect'
//
// 返回参数:无
//
//
//==========================================================================
function SelectAll(Form, CheckBox)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
var i
var intLength = Form.elements.length
for (i = 0; i < intLength; i ++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
var strType = Form.elements[i].type
if (strType == 'checkbox')
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Form.elements[i].checked = true;
}
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//==========================================================================
//
// 代码描述:去除字符串左边空格
//
// 传入参数:str --- 去除之前的字符串 例: ‘ OK’
//
//
// 返回参数:去出以后的字符串
//
//
//==========================================================================
function jsLTrim(str)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
var rtnStr;
rtnStr=""
for (var i = 0; i < str.length; i ++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (str.charAt(i) != " ")
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
rtnStr = str.substr(i);
break;
}
}
return rtnStr;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//==========================================================================
//
// 代码描述:去除字符串右边空格
//
// 传入参数:str --- 去除之前的字符串 例: ‘ OK’
//
//
// 返回参数:去出以后的字符串
//
//
//==========================================================================
function jsRTrim(str)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
var rtnStr;
rtnStr = ""
for (var i = str.length-1; i >= 0; i --)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (str.charAt(i) != " ")
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
rtnStr = str.substring(0,i+1);
break;
}
}
return rtnStr;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//==========================================================================
//
// 代码描述:去除字符串两边空格
//
// 传入参数:str --- 去除之前的字符串 例: ‘ OK ’
//
//
// 返回参数:去出以后的字符串
//
//
//==========================================================================
function Trim(str)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
return(jsLTrim(jsRTrim(str)));
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//==========================================================================
//
// 代码描述:将回车按键 转为 Tab按键
//
// 传入参数:
//
//
// 返回参数:
//
//
//==========================================================================
function Key_EnterToTab()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
if(event.keyCode == 13)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
event.keyCode = 9;
}
}
//==========================================================================
//
// 代码描述:判断日期的大小
//
// 传入参数: Date1 ---日期1 例:'2004-1-1'
// 传入参数: Date2 ---日期2 例:'2004-2-1'
// 传入参数: Compare ---比较符号 例如 '>','<','='
//
// 返回参数: bool--是否成立
//
//==========================================================================
function Est_Date(Date1,Date2,Compare)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
switch(Compare)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
case '>':
if (Date1>Date2)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return true;
}
else
return false;
break;
case '<=':
if (Date1<=Date2)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return true;
}
else
return false;
break;
case '=':
if (Date1==Date2)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return true;
}
else
return false;
break;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//==========================================================================
//
// 代码描述:判断日期的大小
//
// 传入参数: url 例:www.witehouse.com?bs=over
// 传入参数: 参数名称 例:bs
// 返回参数: 参数值
//
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//
//==========================================================================
function QueryString(url,sName)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
var sSource = url;
var sReturn = "";
var sQUS = "?";
var sAMP = "&";
var sEQ = "=";
var iPos;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
iPos = sSource.indexOf(sQUS);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
var strQuery = sSource.substr(iPos, sSource.length - iPos);
var strLCQuery = strQuery.toLowerCase();
var strLCName = sName.toLowerCase();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
iPos = strLCQuery.indexOf(sQUS + strLCName + sEQ);
if (iPos == -1)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
iPos = strLCQuery.indexOf(sAMP + strLCName + sEQ);
if (iPos == -1)
return "";
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
sReturn = strQuery.substr(iPos + sName.length + 2,strQuery.length-(iPos + sName.length + 2));
var iPosAMP = sReturn.indexOf(sAMP);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if (iPosAMP == -1)
return sReturn;
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
sReturn = sReturn.substr(0, iPosAMP);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
return sReturn;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//==========================================================================
//
// 代码描述:判断多行文本框的是否超出字符
//
// 传入参数: txt 例:form.alltxt 多行文本框对象
// 传入参数: maxlen 例:30 允许最大的多行文本的长度
// 返回参数: 无
//
//
//==========================================================================
function JudTxtValue(txt,maxlen)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
if (txt.value.length>maxlen)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
alert('文本框输入超出'+maxlen+'个长度');
txt.value=txt.value.substr(0,maxlen);
}
}
5,在客户端javascript里操作服务端控件:
this.Button1.Attributes.Add("onclick","return upchang();");
function upchang()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
var i=document.Form1.all['ListBox1'].selectedIndex;
if(i>0)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
var val=document.Form1.all['ListBox1'].item(i-1).value;
var txt=document.Form1.all['ListBox1'].item(i-1).text;
document.Form1.all['ListBox1'].item(i-1).value=document.Form1.all['ListBox1'].item(i).value;
document.Form1.all['ListBox1'].item(i-1).text=document.Form1.all['ListBox1'].item(i).text;
document.Form1.all['ListBox1'].item(i).value=val;
document.Form1.all['ListBox1'].item(i).text=txt;
document.Form1.all['ListBox1'].selectedIndex=i-1;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)