Js 动态增加 删除 select multiple 中的值
两个 multiple 相互传值:
function addSingleTableOption(src, dest)
{
var srcObj = document.getElementByIdx(src)
var destObj = document.getElementByIdx(dest)
var srcOpts = srcObj.options;
var destOpts = destObj.options;
var len = srcOpts.length;
for (i = len - 1; i >= 0; i--)
{
if (srcOpts[i].selected)
{
var newOpt = new Option(srcOpts[i].text, srcOpts[i].value);
destOpts.add(newOpt);
srcOpts.remove(i);
}
}
return;
}
将一个文本框中的值赋值给 multiple :
function addOption(){
var value = document.getElementById("date").value;
var destObj = document.getElementById("days");
var destOpts = destObj.options;
if (value.length > 0){
var newOpt = new Option(value, value);
destOpts.add(newOpt);
}
}
删除 multiple 中的值 :
for (i = len - 1; i >= 0; i--){
destObj.remove(i);
}