【发布时间】:2020-09-07 17:07:26
【问题描述】:
目前我可以单击按钮获取数据并显示带有评论回复的 div,就像在 Youtube 上一样,但我想通过再次单击使其消失。这样可以吗?
$(document).ready(function () {
$(".showReplies").click(function () {
let id = $(this).attr('id');
$.ajax({
url: $(this).attr("data-href"),
type: 'get',
success: function (data) {
console.log(data);
console.log(id)
$(`#${id}.replies`).html(data);
}
})
});
});
我尝试添加 display: none 然后将其更改为阻止,或设置 value='show/hide' 然后使用 toggle('show') 但它不起作用。感谢您提前提供任何帮助。
【问题讨论】:
-
您可以在点击监听器的第一行添加`$(
#${id}.replies).html(''");`? -
就在
$(".showReplies").click(function () {的下方?没有帮助。 -
let id = $(this).attr('id');之后。好吧,我添加了一个小例子。
标签: javascript html ajax