jquery - 如何使用 jquery 选择器删除 tr?
问题描述
当我单击remove
按钮时,数据被删除,但我无法删除tr
表中显示的数据。
<tr>
<td>name</td>
<td><button id="removebutton" data-id="?">Remove</button></td>
</tr>
我想选择tr
顶部并将其从 ajax 响应中删除。
我努力了:
$("#removebutton).on("click",function(){
success: function(res){
$(this).parents("tr").remove(); //this doesn't work
}
});
解决方案
尝试arrow function
改用。这确保范围保持在点击事件而不是success()
$("#removebutton").on("click", function() {
.....
success: (res) => {
$(this).parent().remove();
}
....
});
推荐阅读
- solr - 在 Solr 分组搜索结果中定义每组的排序
- vue.js - 如何在 metaInfo - vue spa 中创建动态元标记?
- c# - 手机输入触摸屏
- python - BeautifulSoup Python .text 方法不返回正确的文本
- node.js - 如何在启动 npm 时解决这个问题?
- python - 如何实现带有嵌套字段的表单?
- java - Project Reactor Kafka 的 Zipkin 跟踪
- java - 如何以编程方式在android Q中获取IMSI?
- apache-spark - 如何使用pyspark捕获分组后的单词频率
- firefox - 将证书添加到 certdata.txt 并使用它们构建 firefox