我在下拉列表中填充了一个数组。
单击我想在警报框中显示colorList[i].Color的项目。
演示:http: //jsfiddle.net/Xz9Hz/
HTML:
<div>
<div id="DynaLoad">
</div>
</div>
查询:
$(document).ready(function() {
var colorList = [
{ Color: "#FFFFFF", Name: "White"},
{ Color: "#202020", Name: "Grey"},
{ Color: "#DE2341", Name: "Red"},
];
$('#DynaLoad').append("<select id='cList'></select>");
for (i = 0; i < colorList.length; i++) {
$("#cList").append("<option class='clr'>" +
colorList[i].Name + "</option>");
// Want to alert colorList[i].Color onClick of the particular selection
});
提前致谢。