js 操作listbox
赋值
代码
function select1()
{
var controlname=document.getElementById("ddgame");
var name=document.getElementById("lboxgame");
if(name.options.length>3)
{alert('最多不能超过4项');return false;}
var str=document.getElementById("lboxgame").value;
var t = controlname.options[controlname.selectedIndex].text;
var v=controlname.options[controlname.selectedIndex].value;
name.options.add(new Option(str+t,v));
}
删除
function delete1()
{
var name=document.getElementById("lboxgame");
name.options.remove(name.selectedIndex);
}
得到值
代码
function getvalue()
{
var name=document.getElementById("lboxgame");
var str="";
if(name.options.length==4)
{
for(var i=0;i<=3;i++)
{
if(str=="")
str=name.options[i].value;
else
str=str+","+name.options[i].value;
}
document.getElementById("Hidden1").value=str;
}
else
{alert('只能是4项');return false;}
}