<分区>
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将有助于其他人回答问题。
关闭 5 年前。
标签 javascript jquery css
<分区>
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将有助于其他人回答问题。
关闭 5 年前。
我试图在单击元素后不显示该元素,但是当页面加载时会调用 onclick 方法,然后在我单击它时不会调用它。这是我的代码。
$(document).ready(function() {
$(".close").on('click', function(){
$(this).parent().parent().css("display","none");
});
}
这里有什么问题?
最佳答案
问题不明确。但是您的元素要么从一开始就在 dom 上不可用,要么您没有正确选择要隐藏的元素。
试试这个:
$(document).ready(function() {
$("body").on('click', '.close',function(){
$(this).closest("insert-element-name").css("display","none");
});
}
关于javascript - 单击功能未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47108390/