如何让按钮可点击一次?

问题描述 投票:0回答:1

在我的代码中,我希望按钮可以单击一次。我在下方放置了 2 个按钮,因为我想在单击其中一个按钮时禁用另一个按钮。尽快帮忙非常感谢!

<div style = "position:absolute; left:625px; top:100px; background-color:white;">
    <button type="button" onclick="alert('The guy walks away disapointed, I think I made the wrong decision')" >Detain</button>
    <button type="button" onclick="alert('The guy sighs in relief and looked happy. The guards guide him to the exit. I think I made the right decision')">Free them</button>
         </div>
html button clickonce
1个回答
0
投票

用途:

this.style.display='none'; 

在要删除的 div 内的 onclick 内:

<body>
  <div>
    <button type='button' onclick="alert('message1'); this.style.display='none';">button1</button>
    <button type='button' onclick="alert('message2')">button2</button>
  </div>
</body>
© www.soinside.com 2019 - 2024. All rights reserved.