为什么会出现这个错误,只能填加一个不能删除

josephlong 2002-08-01 03:45:31
<html>
<head>
<SCRIPT language="javascript">
function commuser()
{
var userf=document.userform;
userf.action="/prg/wm/DocAdd.jsp";
userf.submit();
}
function returnemp(inemp)
{
alert("hello one");
var day = inemp;
var month = (document.userappr.month.selectedIndex)+1;
var year = document.calControl.year.value;

if (day != " ") {
dateField.value = year + "-" + month + "-" + day;
window.close()
}
}
function LinkedDropList(oSelA,oSelB){
var dropList1 = oSelA
var dropList2 = oSelB
var autoRemove = true
var ignoreRepeat = false

//+-------------------------------------------------
//this.setAutoRemove=function(bStatus){
// autoRemove = ("boolean" == typeof(bStatus) ? bStatus : false)
//}
autoRemove =true;
//+--------------------------------------------------
//this.setIgnoreRepeat=function(bStatus){
// ignoreRepeat = ("boolean" == typeof(bStatus) ? bStatus : false)
//}

//+--------------------------------------------------
this.move=function(sDirection,nIndex){
if(sDirection=='forward'){
moveForward(nIndex)
}
else{
moveBack(nIndex)
}
}

this.moveAll=function(sDirection){
var oSrc,nTotal

if(sDirection=='forward'){
nTotal=dropList1.length
}
else{
nTotal=dropList2.length
}

for(var i = 0;i < nTotal;i ++){
if (!autoRemove){
this.move(sDirection,i)
}
else{
this.move(sDirection,0)
}
}

}

//+-------------------------------------------------
function moveBack(nIndex){
move(dropList2,dropList1,nIndex)
}

//+-------------------------------------------------
function moveForward(nIndex){
move(dropList1,dropList2,nIndex)
}

//+--------------------------------------------------
function move(oSrc,oTagert,nIndex){
var oCurOption

if(typeof(nIndex)=="undefined"){

if (-1 == oSrc.selectedIndex)
return
oCurOption=oSrc.options[oSrc.selectedIndex]
}
else{
oCurOption=oSrc.options[nIndex]
}

//check if it has added
if (!ignoreRepeat){
for(var i=0;i<oTagert.length;i++){
if(oCurOption.value == oTagert.options[i].value){
alert(oTagert.options[i].value)
oTagert.options[i].selected=true
return
}
}
}

//move element
oTagert.appendChild(oCurOption.cloneNode(true))
if(autoRemove){
oSrc.removeChild(oCurOption)
}
}

dropList1.ondblclick = moveForward
dropList2.ondblclick = moveBack

}

var ld
function window.onload(){
ld = new LinkedDropList(userappr.selsour,userappr.selde)

}

</SCRIPT>

<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<form name="userappr" method="post" >
<table width="100%" border="1" bgcolor="#CCCCCC" height="100%">
<tr>
<td colspan="3">xxx</td>
</tr>
<tr>
<td width="41%">待选人员:</td>
<td rowspan="2" width="10%">
<input type="button" name="useradd" value="添加 ->" onclick="ld.move('forward')">
<input type="button" name="userdel" value="<- 删除" onclick="ld.move('back')">
<input type="button" name="alladd" value="全加 >>" onclick="ld.moveAll('forward')">
<input type="button" name="userreset" value="<< 重置" onclick="ld.moveAll('back')">
</td>
<td width="49%">已选人员:</td>
</tr>
<tr>
<td width="41%">
<select id="selsour" name="selsour1" size="10" style ="width:120">
<option>hello</option>
<option>daniel</option>
<option>joseph</option>
<%

%>
</select>
</td>
<td width="49%">
<select id="selde" name="selde" size="10" style ="width:120">
</select>
</td>
</tr>
<tr>
<td colspan="3">机构:
<select name="dropBranch" onChange="javascript:submit()">
<option></option>
</select>
部门:
<select name="select3">
</select>
<input type="button" name="Submit" value="确定" style="background-color: #DADFD0; border: 1 solid #A0AE88" class="btn" onClick="javascript:commuser()">
<input type="reset" name="Submit2" value="取消" style="background-color: #DADFD0; border: 1 solid #A0AE88" class="btn" onClick="javascript:window.close()">
</td>
</tr>
</table>
</form>
</body>
</html>
...全文
52 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
JavaCoffee 2002-08-01
  • 打赏
  • 举报
回复
给你一个这方面的例子,你参考一下:
<script language="javascript">

function addUserToSelect()
{
var oSeleSrc;
var oSeleDest = document.all("selRoleUser")
oSeleSrc = document.all("selUserList");
AddSelectedItem(oSeleSrc,oSeleDest)

}

function removeUserFromSelect()
{
var oSele = document.all("selRoleUser")
DeleteSeletedItem(oSele);
}

function AddSelectedItem(oSelSrc,oSelDest)
{
try
{
var iIndexSrc,iIndexDest;
var sValue,sInnerText;
var isExistItem;
var oOption;

var sArr,sUserID,sUserName,sUserType;
var isGroup = false;

if(oSelSrc.selectedIndex == -1)
return false;

for(iIndexSrc = 0; iIndexSrc < oSelSrc.options.length; iIndexSrc ++)
{
if(oSelSrc.options(iIndexSrc).selected)
{

isExistItem = false;
sValue = oSelSrc.options(iIndexSrc).value;

for(intIndexDest = 0; intIndexDest < oSelDest.options.length; intIndexDest ++)
{
if(oSelDest.options(intIndexDest).value == sValue)
{
isExistItem = true;
}
}
if(!isExistItem)
{
oOption = document.createElement("OPTION");
oSelDest.options.add(oOption);
oOption.innerText = oSelSrc.options(iIndexSrc).innerText;
oOption.value = sValue;
oOption = null;
}

}
}
return true;
}
catch(e)
{
alert(e.description);
}

}

function DeleteSeletedItem(objSeleDel)
{
try
{
var intIndex;
var intLength;

intLength = objSeleDel.options.length;

if(objSeleDel.selectedIndex == -1)
return false;

var sValue;
var sArr,sUserID;

for(intIndex = 0; intIndex < intLength; intIndex ++)
{
if(objSeleDel.selectedIndex != -1)
{
sValue = objSeleDel.options(objSeleDel.selectedIndex).value;

objSeleDel.options.remove(objSeleDel.selectedIndex);
}
}

return true;
}
catch(e)
{
alert(e.description);
}
}
function addallUserToSelect()
{
removeallUserFromSelect()
i=0
for (i=0;i<document.all.selUserID.length;i++)
{
oOption = document.createElement("OPTION");
document.all.selRoleUser.options.add(oOption);
oOption.innerText = document.all.selUserID.options(i).innerText;
oOption.value = document.all.selUserID.options(i).value;
oOption = null;
}
}
function removeallUserFromSelect()
{
lengths=document.all.selRoleUser.length;
for(i=0;i< lengths;i++)
{
document.all.selRoleUser.options.remove(0);
}
}
</script>
<body>
<div align="center">
<center>
<table border="0" width="100" cellspacing="1">
<tr>
<td width="16%">
<select id="selUserList" size="1" name="selUserID" multiple style="width: 120; height: 140" ondblclick="document.all.addoption.onclick();">
<option value="1">aaaaa</option>
<option value="2">bbbbb</option>
<option value="3">ccccc</option>
<option value="4">ddddd</option>
<option value="5">eeeee</option>
</select>
</td>
<td width="19%">
<input class="userbutton" type="button" value=" 增加>>" name="addoption" onclick="addUserToSelect()"><br>
<input class="userbutton" type="button" value="<<删除 " name="deloption" onclick="removeUserFromSelect()"><br>
<input class="userbutton" type="button" value=" 全加>>" name="addalloption" onclick="addallUserToSelect()">
<input class="userbutton" type="button" value="<<全删 " name="delalloption" onclick="removeallUserFromSelect()">
</td>
<td width="65%">
<select id="selRoleUser" size="1" name="selRoleUser" multiple style="width: 120; height: 140" ondblclick="document.all.deloption.onclick();">
</select></td>
</tr>
</table>
</center>
</div>
</body>

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧