gpt4 book ai didi

javascript - 锁定和解锁按钮

转载 作者:行者123 更新时间:2023-11-28 04:44:30 25 4
gpt4 key购买 nike

我想创建一个脚本来锁定和解锁 2 个按钮。如果显示 div,则锁定“Tout déplier”按钮并解锁“Tout plier”按钮,但如果隐藏 div,则锁定“tout plier”按钮并解锁“Tout deplier”按钮。

我的代码,按钮:

<input  type="button" name="answer" class="Button"  value="Tout plier" onclick="hideDiv()" /> 
<input type="button" name="answer" class="Button" value="Tout déplier" onclick="showDiv()" />

显示和隐藏 div 的 javascript :

function showDiv() {
document.getElementById('content_caract_1').style.display = "block";
document.getElementById('content_caract_2').style.display = "block";
document.getElementById('content_caract_3').style.display = "block";
document.getElementById('content_caract_4').style.display = "block";
}

function hideDiv() {
document.getElementById('content_caract_1').style.display = "none";
document.getElementById('content_caract_2').style.display = "none";
document.getElementById('content_caract_3').style.display = "none";
document.getElementById('content_caract_4').style.display = "none";
}

最佳答案

通过锁定和解锁,我假设禁用和启用按钮。如果我是正确的,请尝试下面的代码,这可能会有所帮助。

function showDiv($this) {
enableAllButtons();
$this.disabled = true;
document.getElementById('content_caract_1').style.display = "block";
document.getElementById('content_caract_2').style.display = "block";
document.getElementById('content_caract_3').style.display = "block";
document.getElementById('content_caract_4').style.display = "block";
}
function hideDiv($this) {
enableAllButtons();
$this.disabled = true;
document.getElementById('content_caract_1').style.display = "none";
document.getElementById('content_caract_2').style.display = "none";
document.getElementById('content_caract_3').style.display = "none";
document.getElementById('content_caract_4').style.display = "none";
}
function enableAllButtons(){
var buttons = document.getElementsByName('answer');
for(i=0; i<buttons.length; i++)
{
var tempButton = buttons[i];
tempButton.disabled = false;
}
}
     <input  type="button" name="answer" class="Button"  value="Tout plier" onclick="hideDiv(this)" /> 
<input type="button" name="answer" class="Button" value="Tout déplier" onclick="showDiv(this)" />

关于javascript - 锁定和解锁按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52604453/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com