简体   繁体   English

如何制作一个脚本来关闭网站上的所有照片?

[英]How to make a script that will turn off all photos on the site?

EDIT: I've asked too many questions so I will just leave the part which was 
solved in comment.

The second concern is another button that will disable all the photos that are on the site to be seen by te user.第二个问题是另一个按钮,它将禁用网站上的所有照片,供用户查看。 When you press it again, the photos will be seen again.再次按下时,将再次看到照片。 SOLVED解决了

I assume it should be done in Javascript, but I'm just starting with learning it, so any help would be much appreciated.我认为它应该在 Javascript 中完成,但我只是从学习它开始,所以任何帮助将不胜感激。

I would like to add functionality to my page.我想向我的页面添加功能。

I have not fully understand the behavior of the first button.我还没有完全理解第一个按钮的行为。 The second button is pretty simple: just make a script that fetches all the images in the page and sets them to display="none";第二个按钮非常简单:只需编写一个脚本来获取页面中的所有图像并将它们设置为 display="none";

<script>
var toggle = true;

function imagesToggle(){
    var images = document.getElementsByTagName('img'); 
    if(toggle == true){
        for(var i = 0; i < images.length; i++) {
            images[i].style.display="none";
        }
        toggle = false;
    }
    else{
            for(var i = 0; i < images.length; i++) {
            images[i].style.display="block";
        }
        toggle = true;
    }
}
</script>

And in the button, add the onclick property:在按钮中,添加 onclick 属性:

<button onclick="imagesToggle()">Click on me</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM