gpt4 book ai didi

jquery - 使用 jQuery 添加然后删除元素

转载 作者:行者123 更新时间:2023-12-01 03:00:36 25 4
gpt4 key购买 nike

尝试在 mouseenter 上附加一个元素,然后在 mouseleave 上删除相同的元素。

$(#foo).mouseenter(function (){
$(this).append(#bar);
});
$(#foo).mouseleave(function (){
$(this).remove(#bar);
});

不起作用,我做错了什么吗?

最佳答案

不引用字符串文字似乎是最明显的事情。您尝试过吗:

$("#foo").mouseenter(function (){
$(this).append("#bar");
});
$("#foo").mouseleave(function (){
$(this).remove("#bar");
});

jQuery 的元素选择器函数(即 $())需要一个包含 CSS 样式选择器的字符串,例如 ".someClass""#someId ”“div span.label”。传递那些不带引号的东西是一个语法错误。

关于jquery - 使用 jQuery 添加然后删除元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10712963/

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