javascript - 如何使用javascript创建动态ID,然后链接到轮播上的帖子人口?
问题描述
我希望帖子轮播上的用户将我发送到链接而不是帖子,并且何时过期自动删除。你应该知道我不是javascript专家,我做了这个非常基本的。
这是页面https://thecrescentbeachclub.com/events/upcoming-events/我不知道是否有人可以帮助我改进此代码,或者创建另一个。
客户添加带有特色图片的帖子,然后我们使用此模块显示轮播(他们喜欢现在的显示方式,您应该知道我也没有做这个网站,所以很难改变客户的想法),当我添加了一个自动过期程序,当事件完成时,帖子被删除,一切都很好。情况是,在我发送给您的链接上,我添加了链接的下一个代码,因为我不希望人们转到帖子,我希望他们转到外部链接。
jQuery(function($){
$('.qode-bct-posts .qode-bct-post').each(function(){
$(this).attr('id',$(this).index()+1);
});
$('.qode-bct-posts .qode-bct-post .qode-bct-post-image img').each(function(){
$(this).unwrap();
});
$('#1').wrap('<a style="width: 100%; display: inline-block; vertical-align: top;" href="https://www.eventbrite.com/e/easter-at-the-beach-buffet-brunch-tickets-58504343065" target="_blank" itemprop="url"></a>');
$('#2').wrap('<a style="width: 100%; display: inline-block; vertical-align: top;" href="#" target="_blank" itemprop="url"></a>');
$('#3').wrap('<a style="width: 100%; display: inline-block; vertical-align: top;" href="#" target="_blank" itemprop="url"></a>');
});
现在的问题是,当一个帖子被自动删除时,链接是错误的,例如,第一个帖子的 ID 为 1,但当过期时消失,现在 ID 为 2 的帖子的链接为 1。我有手动更改链接,这就是我们想要避免的。
有人可以帮助我使 ID 动态化,这样当帖子过期并消失时,其他人仍然会保留正确的链接吗?我希望我自己解释。
解决方案
如果您必须从 html 中删除特定的 Id 元素。将 #1 替换为您想要删除的任何内容。
$('.qode-bct-posts #1').parent().closest('a').remove();
您需要传递 id 才能删除特定元素。
推荐阅读
- angular - 角度表单生成器验证
- javascript - Css - 如何在内联样式中包含不同浏览器的不同属性?
- reactjs - 在 React 数据库调用不起作用时按日期排序 - 只是先返回最旧的
- c# - 如何在 Localhost 中将客户端计算机上的网站作为安全 Web 访问
- android - obj.apply{ func1() } 的结果与 obj.func1() 不同
- python - 如何使我的 python 代码可分发?
- c# - 蓝牙设备被检测为低功耗且具有相同 MAC 地址和名称的普通蓝牙设备
- oracle - ORA-06502:PL/SQL:数字或值错误:字符到数字的转换错误 - TO_DATE 错误?
- javascript - svg 元素在浏览器中的位置
- amazon-web-services - 在未显示站点地图和博客的 aws 静态网站上部署 nuxt