您好我有一个按钮,通过this
到如下的函数:通行证[对象物体]对函数
<div class="itemRow">
<a href="javascript:void(0);" onclick="deleteMessage(this, 3);" class="btn btn-primary">Delete</a>
</div>
为了保持这个简单起见,我已经删除了itemRow
DIV内的其它元件。基本上这个div包含关于一个项目的信息以及一个删除该项目的按钮。每个项目都有一个itemRow
div,因此页面上有很多。我想确定按钮调用来自哪一行,以便在实际删除项目时删除正确的行。
function deleteMessage(row, itemNum){
$('#deleteMsgModal').modal('show');
//Change the modal buttons's onclick handler
$("#deleteConfirmBtn").click(function(){ deleteRow(row, itemNum);});
}
所以上面的函数将显示一个模式,要求确认。模式中按钮的onclick处理程序接受this
对象和项目编号,然后转到单独函数deleteRow
,该函数实际删除该行并删除该行。
function deleteRow(contentRow, itemNo){
var item = itemNo;
//do some ajax code to remove the row from the database...
...
//then once it is removed then to remove the div that is showing the row...
$(contentRow).parent().remove();
}
的问题是,当#deleteConfirmBtn
按钮的点击处理程序this
带一个参数,它显示为[Object object]
这是行不通的。有没有办法解决这个问题,以便最终的功能可以删除正确的div?
当我这样做,onclick处理程序如下所示: 的onclick =“deleteRow($(JavaScript的:无效(0);),3),这将返回以下错误:SyntaxError:missing) – Matt9Atkins
没关系,我看你已经在做$(contentRow).parent()。remove();你在哪里console.log? –