禁用按钮点击但启用另一个按钮 [英] Disable button onclick but enable another button

查看:46
本文介绍了禁用按钮点击但启用另一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面上有两个不同的按钮.我希望在页面加载时启用它们,但是当用户单击一个按钮时,我想禁用另一个按钮.但是,如果他们单击另一个按钮,我希望在启用另一个禁用按钮的同时禁用该按钮.我已经能够禁用 onclick 按钮,但是我无法让另一个按钮重新启用.这是我在页面上的两个按钮.它们不是在表单中,而是在页面上.

I have two different buttons on my page. I want them both to be enabled when the page loads, but when a user clicks one I would like to disable the other button. But if they click the other button, I would like that button to disabled as well while enabling the other disabled button. I have been able to disable the button onclick, but I'm having trouble getting the other button to re-enable . Here are the two buttons that I have on the page. They are not in a form, just on the page.

<button onclick="down7913.disabled=false" type="submit" class="positive" name="up7913"><img src="check.png" alt=""/></button>

<button onclick="this.disabled=true" type="submit" class="negative" name="down7913"><img src="cross.png" alt=""/></button>

推荐答案

检查此代码,它符合您的口味并且正在工作:

Check this code, it's in your flavour and working:

代码片段 -

<button
    onclick="this.disabled=true;document.getElementById('down7913').disabled=false;"
    type="submit"
    class="positive"
    name="up7913"
    id="up7913"
  >
    First
  </button>

  <button
    onclick="this.disabled=true;document.getElementById('up7913').disabled=false;"
    type="submit"
    class="negative"
    name="down7913"
    id="down7913"
  >
    Second
  </button>

这篇关于禁用按钮点击但启用另一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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