【问题标题】:Why is my button disappearing after being clicked为什么我的按钮被点击后消失了
【发布时间】:2020-10-04 22:52:52
【问题描述】:

我的按钮按照我需要的方式运行,除非单击它时它会完全消失。为什么要这样做?

<script type="text/javascript">
function randomlinks(){
    var myrandom=Math.round(Math.random()*6)
    var links=new Array()
    links[0]="https://abantutogether.org/"
    links[1]="https://abantutogether.org/about-us"
    links[2]="https://abantutogether.org/donate"
    links[3]="https://abantutogether.org/get-involved"
    links[4]="https://abantutogether.org/blog"
    links[5]="https://abantutogether.org/contact-us"
    links[6]="https://abantutogether.org/sponsor-a-child"
  
 
     window.open(links[myrandom])
}
</script>
<form>
<input type="image" src="https://i.postimg.cc/43PDgqnZ/Logo-Pix-Teller-1.png"  value="random link!" onClick="randomlinks()">
</form>

【问题讨论】:

    标签: html forms button


    【解决方案1】:

    当您单击按钮时,会打开另一个选项卡/浏览器窗口并提交页面。这是您期望的行为吗?

    在这种情况下提交表单对我来说听起来很奇怪(form TAG 中没有设置action 属性)。也许您不想在表单中包含此输入,或者您可以通过更改 onclick 属性来避免提交,如下所示:

    onClick="randomlinks(); return false;"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-29
      • 1970-01-01
      相关资源
      最近更新 更多