gpt4 book ai didi

javascript - 如何在javascript函数中传递 `this`作为参数?

转载 作者:行者123 更新时间:2023-11-28 00:54:34 25 4
gpt4 key购买 nike

我在我的项目中使用 JavaScript。

我有HTML table <table id='idDocList'>我正在做append该表上的一些 html 代码如下。但我想隐藏各自的<tr>当用户点击Delete时 anchor 标记。

$("#idDocList").append("<tr><td>" + file.name + "</td><td>" + sz + "</td><td><a onclick=deleteDocument(this,'" + file.name + "')> Delete</a></td></tr>");

如何使用 Jquery 执行此操作?

以下示例不起作用

function deleteDocument(CurAnchorTag, fileName) {
$(CurAnchorTag).closest('tr').hide();
}

我不想使用ID对于 <a>标记,因为我有很多文档。

最佳答案

作为快速修复,您可以像这样使用,

$(CurAnchorTag).closest('tr').hide();

已替换 <tr>tr

您可以像这样使用 jquery 删除内联函数调用,

$("#idDocList").on("click", "td a", function() {
$(this).closest("tr").hide();
var filename = $(this).closest("td").prev().text();
});

关于javascript - 如何在javascript函数中传递 `this`作为参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26382706/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com