gpt4 book ai didi

javascript - 更改选择字段后不出现输入字段

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

一旦用户在下拉菜单中选择“取消”,输入字段就会出现在用户面前,以便用户可以输入取消的原因。

但是它不起作用。

默认情况下,输入字段处于禁用状态,并且不会向用户显示。

我尝试使用onselect但无济于事。

HTML

<div>
<select placeholder="Status?" onselect="closeReasonAction" name="changeStatus" id="changeStatus" disabled>
<option value="Pending">Pending</option>
<option value="Quoted">Quoted</option>
<option value="Cancelled">Cancelled</option>
<option value="Confirmed">Confirmed</option>
</select>
<input name="closeReason" type="RRField" id="closeReason" style="margin:4px; padding:2px;">
</div>

if (document.getElementById('changeStatus').value != "Cancelled") {

document.getElementById("closeReason").style.opacity = 0;
document.getElementById("closeReason").disabled = true;
}
else if (document.getElementById('changeStatus').value == "Cancelled") {
document.getElementById("closeReason").style.opacity = 1;
document.getElementById("closeReason").disabled = false;
}

一旦用户单击“取消”,此处禁用的输入字段就应该能够并显示以供用户输入

最佳答案

我认为您错过了 onchange 函数,当您更改选择时会发生什么。将 onselect 函数修改为 onchange 函数,并将 opacity:0 添加到输入样式中,并使其最初disabled

function closeReasonAction() {
if (document.getElementById('changeStatus').value != "Cancelled") {
document.getElementById("closeReason").style.opacity = 0;
document.getElementById("closeReason").disabled = true;
}
else if (document.getElementById('changeStatus').value == "Cancelled") {
document.getElementById("closeReason").style.opacity = 1;
document.getElementById("closeReason").disabled = false;
}
}
<div>
<select placeholder="Status?" onchange="closeReasonAction()" name="changeStatus" id="changeStatus" >
<option value="Pending">Pending</option>
<option value="Quoted">Quoted</option>
<option value="Cancelled">Cancelled</option>
<option value="Confirmed">Confirmed</option>
</select>
<input name="closeReason" type="RRField" id="closeReason" style="margin:4px; padding:2px; opacity:0" disabled />
</div>

关于javascript - 更改选择字段后不出现输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56142687/

24 4 0
文章推荐: javascript - 绑定(bind)问题 'this' Angular/Javascript
文章推荐: css - 如何将多个交互式 DIV 添加到 Google Map - 将鼠标悬停在上面时会改变大小
文章推荐: html - CSS Class里面的背景图片到
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com