发布于2024-10-30 10:40 阅读(1041) 评论(0) 点赞(4) 收藏(1)
我在网站页脚创建了一个电子邮件订阅表单。但问题是,当我点击关闭图标时,表单不会消失。
var button = document.querySelector("#close");
button.addEventListener("click", function() {
var t = document.querySelector(div.getAttribute("data-target"));
t.style.display = "none" == t.style.display ? "block" : "none"
});
<div class="hook-section js-common-hook">
<div class="hook-content small-hook-show">
<div class="loader">
Loading...
</div>
<div class="hook-close-btn sprite-img">Close</div>
<div class="top-sec clearfix">
<div class="left-sec sprite-img">
</div>
<div class="right-sec">
<h5>Email Newsletter</h5>
<p>The best of technology updates from India and around the world</p>
</div>
</div>
<div class="bootom-sec">
<form class="hook-form" action='https://feedburner.google.com/fb/a/mailverify?uri=TechLekhak' method='post' onsubmit='window.open
('https://feedburner.google.com/fb/a/mailverify?uri=12c55',
'popupwindow', 'scrollbars=yes,width=550,height=520');return true' target='popupwindow'>
<input placeholder="Enter your email id" name="email" type="text" />
<input value="12c55" name="uri" type="hidden" />
<input value="en_US" name="loc" type="hidden" /><button class="subs-btn">Subscribe Now</button>
</form>
</div>
</div>
</div>
您与查询选择器匹配的内容有误。您尝试获取具有“close”id 的元素,但您的代码中没有该元素。
这可以通过添加id="close"
到您想要触发您定义的点击功能的标签来安排
例子 :
<div id="close" class="hook-close-btn sprite-img">Close</div>
与您要关闭的项目匹配的查询选择器也发生了同样的情况...它不存在,您需要对其进行调整
您可以更改id="toggle"
页面周围以查看那些元素是否打开和关闭
以下是片段
var toggler = document.querySelector("#close");
toggler.addEventListener("click", function() {
var toggleElement = document.querySelector("#toggle");
if (!toggleElement.style.display || toggleElement.style.display === "block") {
toggleElement.style.display = "none";
} else {
toggleElement.style.display = "block";
}
});
<div class="hook-section js-common-hook">
<div class="hook-content small-hook-show">
<button id="close" class="hook-close-btn sprite-img">Close</button>
<div class="top-sec clearfix">
<div class="left-sec sprite-img">
</div>
<div class="right-sec">
<h5>Email Newsletter</h5>
<p>The best of technology updates from India and around the world</p>
</div>
</div>
<div class="bootom-sec">
<form id="toggle" class="hook-form" action='https://feedburner.google.com/fb/a/mailverify?uri=TechLekhak' method='post' onsubmit='window.open
('https://feedburner.google.com/fb/a/mailverify?uri=12c55',
'popupwindow', 'scrollbars=yes,width=550,height=520');return true' target='popupwindow'>
<input placeholder="Enter your email id" name="email" type="text" />
<input value="12c55" name="uri" type="hidden" />
<input value="en_US" name="loc" type="hidden" /><button class="subs-btn">Subscribe Now</button>
</form>
</div>
</div>
</div>
作者:黑洞官方问答小能手
链接:http://www.qianduanheidong.com/blog/article/533411/c8d4d368b8edc654714c/
来源:前端黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 前端黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-3
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!