使用js设置不透明度或关闭模式窗口 [英] Set opacity with js or close modal window

查看:95
本文介绍了使用js设置不透明度或关闭模式窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想关闭"一个模态窗口.这是一个wordpress模板,而且很丑... 我有一个div:

I would like to "close" a modal window. It's a wordpress template and it's ugly... I have a div :

<div class="modal">
    <section style="position:relative;z-index:10;">
        <div style="margin-bottom: -50px; margin-right: 50px; text-align: right;">
            <img src="./wp-content/img.png" alt="Close">
        </div>
        <p><img src="./wp-content/img2.png" alt="test"></p>
    </section>
</div>

当单击带有alt="Close"的img时,我想关闭或将所有div.modal的不透明度设置为0.使用JS可以吗?

And when the img with alt="Close" is clicked, I would like to close or set the opacity of all the div.modal at 0. Is it possible with JS?

推荐答案

jQuery-

$('img[alt*=Close]').click(function() {
    $('.modal').hide();
});

JS-

var img = document.querySelector('img[alt*=Close]'),
       modal = document.querySelector('.modal');
img.addEventListener('click', function() {
    modal.style.display = 'none';
});

这篇关于使用js设置不透明度或关闭模式窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆