javascript - 当我从选择选项中获得现金价值时如何禁用另一个选择选项
问题描述
我有这个代码,我想启用或禁用某个选择框进行交易。我不知道这个代码是正确的希望你能帮帮我。
<select id="paymenttype" class="paymenttype" name="input-paymenttype" onChange="changetextbox()">
<option value="Cash">Cash</option>
<option value="Installment">Installment</option>
</select>
<select id="paymentterms" class="" name="input-paymentterms" disabled="true">
<option value="3">3x</option>
<option value="4">6x</option>
<option value="6">12x</option>
</select>
<script type="text/javascript">
function changetextbox()
{
var e = document.getElementById("paymenttype");
var value = e.options[e.selectedIndex].value;
if (value == "Cash") {
alert('I need to disable payment terms');
}
else{
alert('I need to enable payment terms');
document.getElementById("paymentterms").disable =='false';
}
}
</script>
解决方案
使用它来删除属性:
document.getElementById("paymentterms").removeAttribute("disabled");
推荐阅读
- python - Python lambda:TypeError:'float'类型的参数不可迭代
- regex - 使用 [^] 语法匹配一个单词但不匹配它的反义词
- java - 无法在 Windows 中运行 PMD
- pdf - xsl:fo 在页面序列中增加一个变量?
- angular - 创建一个类以在角度 4 中保存所有自定义验证的正确方法
- c - Atmega16 的端口不工作
- laravel - 合并 Laravel 收集结果,聚合一个字段
- asp.net - django 应用程序中的 IIS 和 SQL Server Windows 身份验证
- uwp - UWP 中的 web 隔间是什么意思?
- java - 解决 Java 接口钻石问题