首页 > 解决方案 > 当我从选择选项中获得现金价值时如何禁用另一个选择选项

问题描述

我有这个代码,我想启用或禁用某个选择框进行交易。我不知道这个代码是正确的希望你能帮帮我。

<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>

标签: javascripthtmldom-events

解决方案


使用它来删除属性:

document.getElementById("paymentterms").removeAttribute("disabled");

推荐阅读