Posted on 2007-08-03 17:02
七郎归来 阅读(923)
评论(0) 编辑 收藏
==========================第一个
<form name="form1">
<script language="javascript">
function left2Right() {
var s1 = document.form1.select1;
var s2 = document.form1.select2;
for (var i = 0; i < s1.options.length; i++) {
var o = s1.options[i];
if (!o.selected) continue;
var contains = false;
for (var j = 0; j < s2.options.length; j++) {
if (s2.options[j].value == o.value) {
contains = true;
break;
}
}
if (!contains)
s2.options[s2.options.length] = new Option(o.text, o.value);
}
}
function right2Left() {
var s1 = document.form1.select1;
var s2 = document.form1.select2;
for (var i = 0; i < s2.options.length; i++) {
var o = s2.options[i];
if (!o.selected) continue;
var contains = false;
for (var j = 0; j < s1.options.length; j++) {
if (s1.options[j].value == o.value) {
contains = true;
break;
}
}
if (!contains)
s1.options[s1.options.length] = new Option(o.text, o.value);
}
}
</script>
<select name="select1" size="10" multiple >
<option value="111">1</option>
<option value="222">2</option>
<option value="333">3</option>
<option value="444">4</option>
</select>
<input name="Submit" type="button" value=">>>" onclick="left2Right();">
<input name="Submit" type="button" value="<<<" onclick="right2Left();">
<select name="select2" size="10" multiple >
<option value="444">4</option>
<option value="555">5</option>
<option value="666">6</option>
</select>
</select>
</form>
==========================第二个
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>javascript select options text value</title>
<meta name="keywords" content="javascript select options text value add modify delete set">
<meta name="description" content="javascript select options text value add modify delete set">
<script language="javascript">
<!--
// Author: i@lxl.cn
// Modify: i@cnlei.com
function watch_ini(){ // 初始
for(var i=0; i<arguments.length; i++){
var oOption=new Option(arguments[i],arguments[i]);
document.getElementById("MySelect")[i]=oOption;
}
}
function watch_add(f){ // 增加
var oOption=new Option(f.word.value,f.word.value);
f.keywords[f.keywords.length]=oOption;
}
function watch_sel(f){ // 编辑
f.word.value = f.keywords[f.keywords.selectedIndex].text;
}
function watch_mod(f){ // 修改
f.keywords[f.keywords.selectedIndex].text = f.word.value;
}
function watch_del(f){ // 删除
f.keywords.remove(f.keywords.selectedIndex);
}
function watch_set(f){ // 保存
var set = "";
for(var i=0; i<f.keywords.length; i++){
set += f.keywords[i].text + ";";
}
confirm(set);
}
//-->
</script>
</head>
<body>
<form name="watch" method="post" action="">
<select id="MySelect" name="keywords" size="10" onchange="watch_sel(this.form)"></select><br>
<script language="javascript">
<!--
watch_ini("我","你","妳","他","她","它","尔"); // 初始关键词
//-->
</script>
<input type="text" name="word" /><br />
<input type="button" value="增加" onclick="watch_add(this.form);" />
<input type="button" value="修改" onclick="watch_mod(this.form);" />
<input type="button" value="删除" onclick="watch_del(this.form);" />
<input type="button" value="保存" onclick="watch_set(this.form);" />
</form>
</body>
</html>