我正在动态创建一个Button,需要添加到li标签
这是我的jsfiddle
http://jsfiddle.net/1ty1v8u1/7/
这是我的代码
function showRestaurantDetailsByLocation(response,locationname)
{
$('.restListings').remove();
$('.addNewRestaurant').remove();
var ulhtml = $('<ul class="restListings"></ul>');
var divhtml = $('<div class="inner-intit"><sub class="sub">Your Favorite Area</sub></div>');
divhtml.append('<br>');
var $newbutton= $('<input/>').attr({ type: 'button', location:locationname , name:'btn1', class:'btn btn-success', value:'Add For'+locationname});
var $ordernow= $('<input/>').attr({ type: 'button',name:'btn1', class:'btn btn-success', value:'Order Now'});
for(var i=0;i<response.length;i++)
{
divhtml.append('<li><h6>'+response[i].area+'</h6><p>'+response[i].address+'</p></li>');
}
divhtml.append($newbutton);
divhtml.append($ordernow);
ulhtml.append(divhtml);
$("#"+locationname).append(ulhtml);
}
我尝试了这些选项
var $ordernow= $('<input/>').attr({ type: 'button', name:'btn2', class:'btn btn-success ordernow', value:'Order Now'});
divhtml.append('<li class="innerChild" user_location="'+locationname+'" vendor_name="'+response[i].vendor_name+'" vendor_id="'+response[i].vendor_id+'" ><h6> '+response[i].vendor_name+'</h6><p>'+response[i].locality+' , '+response[i].area+' </p><p><b>Timings:</b> '+response[i].start_time+' - '+response[i].end_time+'</p><span class="inDeleteInnerSub"></span></li>');
$('<li />').appendTo(ordernow);
方法2:
divhtml.append('<li class="innerChild" user_location="'+locationname+'" vendor_name="'+response[i].vendor_name+'" vendor_id="'+response[i].vendor_id+'" ><h6> '+response[i].vendor_name+'</h6><p>'+response[i].locality+' , '+response[i].area+' </p><p><b>Timings:</b> '+response[i].start_time+' - '+response[i].end_time+'</p><span class="inDeleteInnerSub"></span>ordernow </li>');
方法3:
divhtml.append('<li class="innerChild" user_location="'+locationname+'" vendor_name="'+response[i].vendor_name+'" vendor_id="'+response[i].vendor_id+'" ><h6> '+response[i].vendor_name+'</h6><p>'+response[i].locality+' , '+response[i].area+' </p><p><b>Timings:</b> '+response[i].start_time+' - '+response[i].end_time+'</p><span class="inDeleteInnerSub"></span>'+$ordernow+'</li>');
将其显示为对象