首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

【取得ListBox项的有关问题 】

2012-03-11 
【取得ListBox项的问题 】我用的是ASP.NET的ListBox控件:用javascript脚本:document.forms[0].ListBox.optio

【取得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。

热点排行