【问题标题】:Hide image in the link when press link once按一次链接时隐藏链接中的图像
【发布时间】:2018-06-24 13:40:27
【问题描述】:

我有以下脚本。我想要的是,当我按一次链接时,链接中的图像就会消失。我想点击链接后消失的图片是enter.png。

<script>
$(document).ready(function() {
 $(".open_close_doors").click(function(){
   $("#leftdoor_inner").animate({"left": "-=395px"}, "slow");
   $("#rightdoor_inner").animate({"left": "+=395px"}, "slow");

   setTimeout("window.location.href='wall.php';",200);
 });
});
</script>

<a class="open_close_doors" href="#"><img src='img/enter.png' onmouseover=this.src='img/enter_light.png' onmouseout=this.src='img/enter.png'></a>

【问题讨论】:

  • 有什么意义?当您点击链接时,您将在 200 毫秒内到达 wall.php 页面,因此整个页面被替换,您不会在短时间内注意到图像的变化。无论如何,只需将src 设置为空"" 即可使图像消失。
  • 知道怎么写吗?
  • 好的,我明白了,感谢您的帮助...我希望按钮消失的原因是因为人们有时会继续按下按钮 unitl 重定向需要几秒钟。还是谢谢
  • 我已经告诉过你,将src 设置为空"" 以使图像消失。所以this.children[0].src = ""
  • 或者看这个选择你想要的带有src的图片https://stackoverflow.com/questions/6763899/css-hide-all-images-with-matching-src-attribute

标签: javascript jquery html dom


【解决方案1】:

要隐藏图像,可以将其src 属性设置为空:

this.children[0].src = "";

但是,由于您的目标是防止用户多次单击按钮,因此最好让整个链接消失:

this.style.visibility = 'hidden';

这是一个演示(出于演示目的,我将重定向注释掉了):

$(document).ready(function() {
  $(".open_close_doors").click(function() {
    $("#leftdoor_inner").animate({
      "left": "-=395px"
    }, "slow");
    $("#rightdoor_inner").animate({
      "left": "+=395px"
    }, "slow");
    this.style.visibility = 'hidden';
    //setTimeout("window.location.href='wall.php';", 200);
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a class="open_close_doors" href="#"><img src='http://placehold.it/50x50' onmouseover="this.src='http://placehold.it/100x100'" onmouseout="this.src='http://placehold.it/50x50'"></a>

【讨论】:

    猜你喜欢
    • 2019-01-03
    • 2011-10-04
    • 2013-03-17
    • 1970-01-01
    • 2018-10-04
    • 2018-09-02
    • 1970-01-01
    • 2017-01-09
    • 1970-01-01
    相关资源
    最近更新 更多