关闭弹出窗口,如果我点击另一个DIV
我有使用此代码打开一个弹出窗口:关闭弹出窗口,如果我点击另一个DIV
更新:
<ul class="grid cs-style-1">
<?php
$explainname = new wp_query(array ('post_type' => 'explainname'));
if ($explainname->have_posts()) : while ($explainname->have_posts()) : $explainname->the_post();
$explainname_icon = get_post_meta($post->ID,'explainname_icon', true);
$url = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
$imageContent = get_the_content();
$stripped = strip_tags($imageContent, '<p> <a>'); //replace <p> and <a> with whatever tags you want to keep after the strip
?>
<li class="desktop">
<figure>
<img src="<?php echo $url; ?>" alt="<?php the_title(); ?>">
<figcaption>
<h3><?php the_title(); ?></h3>
<span style="text-align:right;font-size: 15px;"><?php echo $stripped; ?></span>
</figcaption>
</figure>
</li>
<li class="popup" onclick="myFunction<?php echo $post->ID; ?>()">
<figure>
<img src="<?php echo $url; ?>" alt="<?php the_title(); ?>">
<span class="popuptext" id="myPopup<?php echo $post->ID; ?>"><?php echo $stripped; ?></span>
</figure>
</li>
<script>
// When the user clicks on <div>, open the popup
function myFunction<?php echo $post->ID; ?>() {
var popup<?php echo $post->ID; ?> = document.getElementById("myPopup<?php echo $post->ID; ?>");
popup<?php echo $post->ID; ?>.classList.toggle("show");
}
</script>
<?php
endwhile; endif;
wp_reset_query();
?>
</ul>
我怎样才能关闭弹出窗口弹出窗口中?
我的意思是,我需要CLASE任何打开弹出,当我在新的div
用这个例子
<script>
$(document).not("#myPopup<?php echo $post->ID; ?>").click(function() {
$('#myPopup<?php echo $post->ID; ?>').hide();
});
</script>
您对selecteddiv的含义是什么?我没有名为selecteddiv的div。并在哪里把这个代码 –
检查它现在添加它后你的脚本 – Adaleni
仍然无法正常工作时,点击另一个div(http://prntscr.com/gq22ye) –
这里是一个解决方案点击。当你点击一个DIV时,它会关闭你的弹出窗口。如果你想要定位所有的弹出窗口,那么你需要给它们一个普通的类名称。
document.getElementsByTagName('div').onclick = function(e){
document.getElementById("myPopup<?php echo $post->ID; ?>").style.display = 'none';
});
抱歉,现在与我合作 –
简单的JavaScript
var popup<?php echo $post->ID; ?> = document.getElementById("myPopup<?php echo $post->ID; ?>");
window.onclick = function() {
if (popup.classList.contains("show")) {
popup.classList.toggle("show");
}
}
我们都在猜测这里使用。没有办法测试这个,没有HTML。你可以发布弹出窗口的HTML和页面吗?否则,我认为你不会找到有用的答案。 –
查看我的更新,,我添加上面的代码 –