61,129
社区成员




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="Gao YiXiang" />
<meta name="email" content="yixianggao@126.com" />
<meta name="keywords" content="javascript dhtml dom" />
<meta name="description" content="I love web development." />
</head>
<body>
<select id="sltTest" multiple size="5">
<option value="0">-- Please select --</option>
<option value="1">option 01</option>
<option value="2">option 02</option>
<option value="3">option 03</option>
<option value="4">option 04</option>
</select>
<script type="text/javascript">
<!--
Array.prototype.indexOf = function(target)
{
var result = -1;
for (var i=0; i<this.length; i++)
{
if (this[i] == target)
{
result = i;
break;
}
}
return result;
};
var oSlt = document.getElementById("sltTest");
oSlt.selectedList = new Array();
oSlt.onchange = function()
{
with (this)
{
var i = selectedList.indexOf(selectedIndex);
if (i == -1)
{
selectedList.unshift(selectedIndex);
}
else
{
options[selectedIndex].selected = false;
selectedList.splice(i, 1);
}
for (var i=0; i<selectedList.length; i++)
{
options[selectedList[i]].selected = true;
}
}
};
//-->
</script>
</body>
</html>