javascript 对ListBox的增 删
假设有2个ListBox,ID分别为lbLeft,lbRight
选中lbLeft里的项添加到lbRight里:
function add()
{
var left;
var right;
left = document.getElementById("lbLeft");
right = document.getElementById("lbRight");
for(var i=0;i<left.length;i++)
{
if(left.options[i].selected)
{
//判断该项是否已经存在
for(j=0;j<right.length;j++)
{
if(right.options[j].value==left.options[i].value)
{
return;
}
}
right.add(new Option(left.options[i].text,left.options[i].value));
}
}
}
删除lbRight里的项:
function del()
{
right=document.getElementById("lbRight");
for(i=right.length-1;i>=0;i--)
{
if(right.options[i].selected)
{
right.remove(i);
}
}
//重新赋值
for(j=0;j<right.length;j++)
{
document.getElementById("txtAllName").value+=right.options[j].text+",";
document.getElementById("txtAllID").value+=right.options[j].value+",";
}
}
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |