在上面的 javascript 对象中,我希望能够找到类 .inject 并在其上附加一个 ul, li。如何实现?
var $variable = $('<h5>'+ opts.fields.ac_firstname +' '+ opts.fields.ac_lastname+ ' ('+opts.fields.ac_source_id +')</h5><div class="inject"><append ul li here></div><p style="font-weight:bold; margin:1em 0 0;">View Summary</p><div class="bcCallToAction"><a href="" target="_blank">Visit google.com</a></div>');
试过这个,但效果很好
if(opts.fields.ac_othernames.length > 1){
$.each(opts.fields.ac_othernames, function(k, v){
altNameMarkup += '<li>' + v + '</li>';
});
var $ulAltNms = $('<ul>');
$ulAltNms.append(altNameMarkup);
$variable.find('.inject').append($ulAltNms);
}