javascript - JQUERY Show overlay when button click work only first time. What's wrong?
问题描述
Why my overlay 'p' (bg purple with yellow text) is showing only once after button clicked, even if I have toggle the function?
Have a look to my codepen to test the issue:
https://codepen.io/cat999/project/editor/AEeEdg
$('.animate-this').click(function() {
$('p').slideToggle("fast");
});
Easy way to fix this?
解决方案
当可见时,该.animate-this
元素被隐藏。<p>
您可以将相同的功能添加到 中<p>
,然后它将起作用。
$('.animate-this, p').click(function() {
$('p').slideToggle("fast");
});
但是,我建议不要将事件投标给一个标签,而是一个类。因此,您只需将类添加.animate-this
到<p>
标签中,它也可以工作,如下所示:
<p class="animate-this">If you click i need to show up again!</p>
推荐阅读
- asp.net-core - 如何使用 Xunit 在 Visual Studio 代码中调试非测试项目
- sql-update - 用字符更新 sql 问题
- python - 由于错误“WebDriverException:'chromedriver.exe' 可执行文件需要在 PATH 中”,无法运行 webdriver.chrome()。
- qt - 如何在 QML 中实现对象之间的单一连接?
- azure-functions - 在 Azure Functions 中绑定到 json 有效负载和 http 触发器的标头
- airflow - 任务在排队且未恢复时在 Airflow 中移动到已移除状态
- javascript - 使用javascript jquery将html附加到具有指定类的按钮最近的div
- node.js - Amazon SES verifyEmailIdentity 未发送电子邮件
- swagger - Swagger 是否可以为 POST 和 PATCH 显示不同的模型视图,即一次写入属性?
- postgresql - 将 DialogflowChatbot 与 PostgreSQL 数据库连接