87,907
社区成员
发帖
与我相关
我的任务
分享
<script type="text/javascript">
function add()
{
var right = document.getElementById("right")
var left = document.getElementById("left")
var text = left.options[left.selectedIndex].text
for(var i=0;i<right.options.length ;i++ )
{
if(text=="管理员")
{
if(right.options[i].text.indexOf("员工")>-1)
{
alert("管理员不能与员工在一起")
return;
}
}
else
{
if(right.options[i].text.indexOf("管理员")>-1)
{
alert("管理员不能与员工在一起")
return;
}
}
if(text==right.options[i].text)
return;
}
right.options.add(new Option(text,""))
}
function del()
{
var right = document.getElementById("right")
if(right.selectedIndex>=0)
right.options[right.selectedIndex] = null
}
</script>
<body>
<table>
<tr>
<td>
select1<br>
<select id="left" size="10">
<option>管理员</option>
<option>crm员工</option>
<option>org员工</option>
</select>
</td>
<td>
<input type="button" value=">>>" onclick="add()" />
<BR><BR>
<input type="button" value="删除select2选中项" onclick="del()" >
</td>
<td>
select2<BR>
<select id="right" size="10">
</select>
</td>
</tr>
</table>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<script type="text/javascript">
function $(id){
return document.getElementById(id);
}
function check(){
var sel2 = $("select2");
var text = "|";
for(var i=0; i<sel2.length; i++){
text += sel2.options[i].text + "|";
}
if(text.indexOf("|管理员|") >= 0 && (text.indexOf("|crm员工|") >= 0 || text.indexOf("|org员工|") >= 0)){
alert("出错了!");
}else{
alert("OK!");
}
}
</script>
<select id="select1">
<option>管理员</option>
<option>crm员工</option>
<option>org员工</option>
</select>
<input type="button" value=">>>>" onclick="check()" />
<select id="select2">
<option>管理员</option>
<option>crm员工</option>
<option>org员工</option>
</select>
</body>
</html>