循环浏览wordpress文章,并使用js添加一个css类



我希望你今天过得愉快:(

我目前正在开发一个插件。我想循环浏览所有文章:点击=>当弹出窗口关闭时打开弹出窗口=>显示此内容。。。我的代码只适用于第一篇文章。对不起,如果这对你来说微不足道,如果你有链接或教程可以建议我,我很感兴趣:(

谢谢!

function socialLocker() {
let sl = document.querySelector(".ws-sl-container");
let slc = document.querySelector(".ws-sl-content");
document.querySelectorAll(".ws-sl-box-for-social-medias a").forEach(function(ele) {
ele.onclick = function(e) {
var web_window = window.open(this.href, 'Share Link', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600,top=' + (screen.height/2 - 300) + ',left=' + (screen.width/2 - 300));
var check_window_close = setInterval(function() {
if (web_window.closed) {
clearInterval(check_window_close);
sl.style.display = "none";
slc.style.display = "block";
}
}, 1000);
e.preventDefault();
};
});
};

选择文档中的元素似乎有问题。

您可以使用next选择器:https://api.jquery.com/next/而不是全选并使用foreach循环。使用next,您将获得最接近的元素。

假设您列表中的所有帖子都有一个类为trigger的按钮,单击后会显示一个类别为popup的弹出窗口。

<script>
jQuery(document).ready(function(){
jQuery(".popup").hide(); /* hide all popups */
jQuery(".trigger").click(function(){ /* when button is clicked */
jQuery(this).next(".popup").slideToggle(); /* toggle the closest popup */
});
});
</script>

这样,(this)元素上的单击/操作(您希望在关闭时进行(将影响最近的元素。

最新更新