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 に答える