2014-10-18 10 views

回答

0

繼續以前的question,您應該使用自定義data-*前綴屬性將您的產品ID添加到按鈕。像

'<input class="Btnremove" data-id="' + data[i].ProductId + '"/>' 

可使用.data()$(this).data('id')

代碼中獲取

for (var i = 0; i < len; i++) { 
    if (data[i].ProductId && data[i].Name && data[i].ShortDescription && data[i].MediumImage && data[i].Price && data[i].IconImage) { 
     txt += .... 
     + '<div class="cartremove"><input class="Btnremove" type="submit" value="Remove" data-id="' + data[i].ProductId + '"/></div>' + "</br>"; 
    } 
} 
$(document).on('click', ".Btnremove", function(event) { 
    $.getJSON('@Url.Action("Deletecart", "home")', { 
     id: $(this).data('id') 
    }, function(data) { 
     location.reload(true) 
    }); 
}); 
0

你可以使用查詢字符串,可以讓你容易理解

的$(document) .on('click','.Btnremove',功能(事件){

警報( '的FeO')

$ .getJSON( 「@ Url.Action(」 Deletecart 「 」家「) 」+「?ID = '值'」,

location.reload(true), function (data) { 

} ); });

相關問題