即時嘗試在這裏做的是獲取單擊函數上的表的id,然後當我單擊刪除按鈕時,它會得到該id並將其刪除。將變量從一個Jquery函數傳遞給另一個
$("table tr").click(function() {
var id;
$(this).removeClass('table-hover');
$(this).css("background-color", "#4682B4");
id = $(this).find(".id").html();
alert("Are you sure you want to delete data with id = " + id); //using just to check if its getting the id of the row
});
$('.btnDelete').click(function() {
$.ajax({
contentType: 'application/json; charset=utf-8',
dataType: 'json',
type: 'POST',
url: 'EmployeeDelete',
data: JSON.stringify({ id: id }),
success: function (data) {
}
});
});
我在做什麼錯在這裏
你存儲的ID表的TR它被認爲是固定的嗎? –
即時獲取tr的id並將其保存到var id –