jquery or JS create child element and assign an ID
This question already has an answer here:
Try this
$("#fDistList").append('<option id="'+ item.ID + '">' + item.GROUP_NAME + '</option>');
When you do
$("option").attr('id', item.ID);
you are reselecting all option
elements and setting their ID attribute.
你可以像这样做,一次通过
$('<option/>',{
text: item.GROUP_NAME,
id:item.ID
}).appendTo('#fDistList');
链接地址: http://www.djcxy.com/p/83348.html