日期:2014-05-16  浏览次数:20402 次

【取得ListBox项的问题 】
我用的是ASP.NET的ListBox控件:

用javascript脚本:
document.forms[0].ListBox.options.add(new   Option( "123 "));  
添加的项没法再用以下脚本取出来:
document.forms[0].ListBox.value

请问怎么回事?   怎么取到手动添加的项呢?

------解决方案--------------------
document.forms[0].ListBox.options.add(new Option( "text1 ", "value1 "));

------解决方案--------------------
要先判断是否被选中
JScript code

var ListBox=window.document.getElementById("ListBox");
var ListBoxlength=ListBox.length;
for(var i=0;i<ListBoxlength;i++)
{
  if(ListBox.options[i]!=null&&ListBox.options[i].selected==true)
   {
     var v = ListBox.options[i].value;
     var t = ListBox.options[i].text;
   }
}

------解决方案--------------------
document.forms[0].ListBox.options.add(new Option( "123 ","123"));
option前两个参数前面的表示显示的文本,后面的表示value。