我有字符串数组like
‘United States’,‘Canada’,‘Argentina’,‘Armenia’,‘Aruba’,
‘Australia’,‘Austria’,‘Azerbaijan’,‘Bahamas’,‘Bangladesh’,
‘Belarus’,‘Belgium’**,… etc.
我想从字符串数组创建一个动态列表,如下所示: –
<ul class="mylist" style="z-index: 1; top: 474px; left: 228px; display: none; width: 324px;" > <li class="ui-menu-item" role="menuitem"> <a class="ui-all" tabindex="-1"> United States </a> </li> <li class="ui-menu-item" role="menuitem"> <a class="ui-all" tabindex="-1"> Canada </a> </li> <li> .... </li> ..... </ul>
如何使用jQuery?
解决方法
var countries = ['United States','Canada','Argentina','Armenia']; var cList = $('ul.mylist') $.each(countries,function(i) { var li = $('<li/>') .addClass('ui-menu-item') .attr('role','menuitem') .appendTo(cList); var aaa = $('<a/>') .addClass('ui-all') .text(countries[i]) .appendTo(li); });