这个怎么错了?

mustapha 2003-05-30 05:18:25
请看下面一段代码(可存为1个html文件),我有连续添加相同元素时禁止添加的代码,但是没效果,还是添加上去了。为什么?

<table id="table1" width="495" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="150"> <div align="center">
<input name="textleibie" type="text" id="textleibie" value="a" size="20">
</div></td>
<td width="141" rowspan="2"> <div align="center"> </div></td>
<td width="204" rowspan="9"><select name="selectcombine" size="10" id="selectcombine" multiple style="width:200px;">
</select></td>
</tr>
<tr>
<td rowspan="8"><div align="center">
<select name="selectleibie" id="selectleibie" size="10" multiple style="width:150px;"onchange="Javascript:textleibie.value=selectleibie.options[selectleibie.selectedIndex].text;">
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
</select>
</div></td>
</tr>
<tr>
<td><div align="center">
<input name="Submit->" type="button" id="Submit->" style="cursor: hand;height:36;width:36; background-color: #E8EFFF; border: 1 solid #3366CC;" value="->" onclick="add()">
</div></td>
</tr>
<tr>
<td><div align="center"> </div></td>
</tr>
<tr>
<td><div align="center">
<input name="Submit<-" type="button" id="Submit<-" style="cursor: hand;height:36;width:36; background-color: #E8EFFF; border: 1 solid #3366CC;" value="<-" onclick=del()>
</div></td>
</tr>
</table>
<script LANGUAGE="Javascript">
function add()
{
var flag=true
//selectcombine.options.add(new Option("'" + textleibie.value + "'"));}
for(var i=0;i<selectcombine.options.length;i++)
{
if (selectcombine.value==textleibie.value){flag=false;}}
if (flag==true){selectcombine.options.add(new Option(textleibie.value));}
}
function del()
{
if(selectcombine.selectedIndex != -1)
{selectcombine.options[selectcombine.selectedIndex] = null}
}
</script>
...全文
30 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
kingdomzhf 2003-05-30
  • 打赏
  • 举报
回复
<table id="table1" width="495" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="150"> <div align="center">
<input name="textleibie" type="text" id="textleibie" value="a" size="20">
</div></td>
<td width="141" rowspan="2"> <div align="center"> </div></td>
<td width="204" rowspan="9"><select name="selectcombine" size="10" id="selectcombine" multiple style="width:200px;">
</select></td>
</tr>
<tr>
<td rowspan="8"><div align="center">
<select name="selectleibie" id="selectleibie" size="10" multiple style="width:150px;"onchange="Javascript:textleibie.value=selectleibie.options[selectleibie.selectedIndex].text;">
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
</select>
</div></td>
</tr>
<tr>
<td><div align="center">
<input name="Submit->" type="button" id="Submit->" style="cursor: hand;height:36;width:36; background-color: #E8EFFF; border: 1 solid #3366CC;" value="->" onclick="add()">
</div></td>
</tr>
<tr>
<td><div align="center"> </div></td>
</tr>
<tr>
<td><div align="center">
<input name="Submit<-" type="button" id="Submit<-" style="cursor: hand;height:36;width:36; background-color: #E8EFFF; border: 1 solid #3366CC;" value="<-" onclick=del()>
</div></td>
</tr>
</table>
<script LANGUAGE="Javascript">

function add()
{

//selectcombine.options.add(new Option("'" + textleibie.value + "'"));
var flag = true;
for(var i=0;i<selectcombine.options.length;i++)
{
if (selectcombine.options[i].innerText==textleibie.value)
{
flag=false;
}
}
if (flag==true)
{
selectcombine.options.add(new Option(textleibie.value));
}

}
function del()
{
if(selectcombine.selectedIndex != -1)
{selectcombine.options[selectcombine.selectedIndex] = null}
}
</script>

87,907

社区成员

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

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