0

我使用 jQuery 从 ListBoxes 中获取选定的值以存储到数据库中。

var hdn2 = "";
jQuery('select[name$=ListMyITProgramming] > option').each(function () { 
    hdn2 += jQuery(this).attr('value') + ','; 
});
alert(hdn2);

谁能帮我获得选定的文本而不是价值?

4

1 回答 1

3

您可以使用text()

var hdn2 = "";
jQuery('select[name$=ListMyITProgramming] > option').each(function () { 
    hdn2 += jQuery(this).text() + ','; 
});
alert(hdn2);

但是,您可以使用以下方法简化代码(并删除尾随,map()

var hdn2 = jQuery('select[name$=ListMyITProgramming] > option').map(function () { 
    return this.innerHTML; // I used the native DOM property here for speed
}).get().join(',');
于 2013-10-09T13:07:47.707 回答