作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在我的项目中使用 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/
我是一名优秀的程序员,十分优秀!