Js 动态增加 删除 select multiple 中的值 multiple
程序员文章站
2022-05-16 11:45:55
...
两个 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);
}
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);
}
下一篇: 一个亿太难了,我还是现实点吧!