每当有人为汽车制造商添加新数据时,我都会尝试附加一个新按钮。然而,它只是不断添加到同一个按钮。如何根据数据对新按钮进行操作?
$.ajax({
method: 'GET'
url: '/cars/'+ year + '/' + make_id,
dataType: "json",
success: function(data) {
var model = data
$('div#render-cars').append('<button id="car-model">' + model + '</button>');
}
});
答案 0 :(得分:0)
试用此代码。相同的ID不能重复。改为使用类或使用动态ID
$.ajax({
method: 'GET'
url: '/cars/'+ year + '/' + make_id,
dataType: "json",
success: function(data){
var model = data
$('div#render-cars').append('<button class="car-model">' + model + '</button>');