Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用传入的变量创建新的onclick方法_Javascript_Jquery_Twitter Bootstrap - Fatal编程技术网

Javascript 使用传入的变量创建新的onclick方法

Javascript 使用传入的变量创建新的onclick方法,javascript,jquery,twitter-bootstrap,Javascript,Jquery,Twitter Bootstrap,我目前弹出一个引导对话框,以确保用户想要删除某人。当用户说ok时,我需要将传入函数的值传递给实际的delete方法。目前,我尝试的所有方法都将“undefined”作为变量传递 function RemoveTeamMember(peoplePK) { //First remove all old click events(so we can reuse), and re-initialize the modal with our new info $("#ConfirmationDialog

我目前弹出一个引导对话框,以确保用户想要删除某人。当用户说ok时,我需要将传入函数的值传递给实际的delete方法。目前,我尝试的所有方法都将“undefined”作为变量传递

function RemoveTeamMember(peoplePK) {

//First remove all old click events(so we can reuse), and re-initialize the modal with our new info
$("#ConfirmationDialog #ConfirmationOKButton").off('onclick');
$("#ConfirmationDialog .modal-header .modal-title").text("Remove Team Member?");
$("#ConfirmationDialog #ConfirmationText").addClass('text-danger').text("Are you sure you want to remove this team member?");
$("#ConfirmationDialog #ConfirmationOKButton").html("Remove Member");

//$("#ConfirmationDialog #ConfirmationOKButton").prop("onclick", "PerformRemoveTeamMember(" + peoplePK + ")");
//Bind the new click event for the ok button
//$("#ConfirmationDialog #ConfirmationOKButton").bind('click', { param: peoplePK }, PerformRemoveTeamMember);
$("#ConfirmationDialog #ConfirmationOKButton").data("pid", ''+peoplePK+'');
$("#ConfirmationDialog #ConfirmationOKButton").on('click', function () {
    //PerformRemoveTeamMember($(this).data("pid"));
    alert($(this).data("pid"));
});
$("#ConfirmationDialog").modal({
    show: true
});
}
最后,我需要使用peoplePK变量的值将一个新的onclick属性附加到按钮上,这个对话框将在多个操作之间重用。这就是为什么我必须动态构建这个按钮

编辑:添加了RemoveTeamMember的调用方式

'<button type="button" class="btn btn-danger btn-sm" onclick="RemoveTeamMember(' + row[0] + ');">Remove Member</button>';`
“删除成员”`
答:更改了RemoveTeamMember的调用方式 今天早上更改了datatables的形成方式后,行[0]不再像以前那样提供正确的数据,因此更改为

'<button type="button" class="btn btn-danger btn-sm" onclick="RemoveTeamMember(' + data + ');">Remove Member</button>'
“删除成员”

这完全解决了这个问题。

您认为我们有足够的信息来回答您的问题吗?RemoveTeamMember是如何命名的?您可能正在发送一个未定义的variable@Patrick-Evans的“RemoveTeamMember”由一个动态构建的按钮调用。它是这样建造的删除成员“;”我已检查是否传入了该值correctly@Echofiend您没有在此处委派事件,请尝试测试它:
$(文档)为了澄清,正确调用了“PerformRemoveTeamMember”方法。但是,我需要传入的值变为“未定义”