嘿所有人我是新手学习j-query而且我很抱歉我的英语不好。
这是我的ajax电话
// Get All Designaions on Department Change
$("#departmentDropdownForBody").change(function (evt) {
var departmentId = $("#departmentDropdownForBody").val();
//Prevent the browser default
evt.preventDefault();
$.ajax({
type: 'GET',
url: '@Url.Action("GetDesignationFilteredByIds", "Designation")',
data: { CompanyId: 0, BusinessUnitId: 0, DepartmentId: departmentId },
dataType: 'JSON',
traditional: true,
success: function (response) {
$('#desigTbody').html('');
var tRow = '';
for (var i = 0; i < response.length; i++) {
tRow += '<tr><td class="hide" id="depId">' + response[i].DepartmentId + '</td>'
tRow += '<tr><td class="hide" id="desId">' + response[i].DesignationId + '</td>'
tRow += '<tr><td>' + response[i].CompanyName + '</td>'
tRow += '<td>' + response[i].BusinessUnitName + '</td>'
tRow += '<td>' + response[i].DepartmentName + '</td>'
tRow += '<td>' + response[i].DesignationName + '</td>'
tRow += '<td><button type="button" id="editBtn" onclick="getDesignation(this.DepartmentId,this.DesignationId)" data-toggle="modal" data-target="#modal-default" ><span class="fa fa-edit" /></button></td></tr>';
};
$('#desigTbody').append(tRow);
},
error: function () { }
});
});
请阅读此ajax电话。我想在我的按钮上传递两个参数,点击每行打印。请帮忙。
答案 0 :(得分:0)
我建议您使用cutom data-*
属性来保留任意数据,这些属性可以使用.data(key)
tRow += '<td><button type="button" class="editBtn" data-departmentid="' + response[i].DepartmentId + '" data-designationid="' + response[i].DesignationId + '" data-toggle="modal" data-target="#modal-default" ><span class="fa fa-edit" /></button></td></tr>';
使用Event Delegation绑定动态元素的事件处理程序
$('#desigTbody').on('click', '.editBtn', function () {
var departmentid = $(this).data('departmentid');
var designationid = $(this).data('designationid');
getDesignation(departmentid, designationid);
});
注意:HTML中的标识符必须是唯一的。