gpt4 book ai didi

javascript - 如何在php中选择一个时禁用下拉菜单

转载 作者:行者123 更新时间:2023-11-28 19:22:45 26 4
gpt4 key购买 nike

有人可以帮我修复我的代码吗?我的问题是如何在选择一个投递箱时禁用另一个投递箱?我正在使用 PHP 和 JavaScript 编程语言。我希望任何人都可以帮助我,因为这非常重要。

这是我的代码:

    <head>
<script type = "text/javascript">
function disableDrop(){
if(frmMain.sltMain.options[1].selected){
frmMain.sltSecondary.disabled = true;
}
else{
frmMain.sltSecondary.disabled = false;
}
}
</script>
</head>

<form ID = "frmMain">

<select ID = "sltMain" onchange = "disableDrop();">
<option value = "onetime" selected>One-Time</option>
<option value = "recurring">Recurring</option>
</select>

<select ID = "sltMain" onchange = "disableDrop();">
<option value = "onetime">One-Time</option>
<option value = "recurring" selected>Recurring</option>
</select>
</form>

最佳答案

试试这个:Demo

HTML 编码:

  <select ID = "sltMain" onchange = "disableDrop(this);">
<option value = "onetime" selected>One-Time</option>
<option value = "recurring">Recurring</option>
</select>

<select ID = "sltSecondary" onchange = "disableDrop1(this);">
<option value = "onetime">One-Time</option>
<option value = "recurring" selected>Recurring</option>
</select>
</form>

JAVASCRIPT:

function disableDrop(elem) {

if(elem.value == 'recurring'){

document.getElementById('sltSecondary').disabled = true;
}
else{
document.getElementById('sltSecondary').disabled = false;
}

}
function disableDrop1(elem) {


if(elem.value == 'onetime'){

document.getElementById('sltMain').disabled = true;
}
else{
document.getElementById('sltMain').disabled = false;
}

}

关于javascript - 如何在php中选择一个时禁用下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28500461/

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