gpt4 book ai didi

javascript - 禁用 numericTextBox onClick 单选按钮单击

转载 作者:行者123 更新时间:2023-11-30 13:47:51 25 4
gpt4 key购买 nike

我有单选按钮和数字文本框。我希望当单选按钮 ="y"时 numericTextBox 不会禁用。我目前正在尝试但效果不佳。我在这里使用 onClick="consign()"。是我遗漏了什么吗?

HTML :

<div class="k-edit-label">
<label for="consignment">Consignment</label>
</div><div>
<input class="k-radio" id="yes3" name="consignment" type="radio" value="y" onClick="consign()" data-bind="checked:consignment">
<label class="k-radio-label" for="yes3">Yes</label>
<input class="k-radio" id="no3" name="consignment" type="radio" value="n" data-bind="checked:consignment">
<label class="k-radio-label" for="no3" style="margin-left: 30px; margin-right:20px;">No</label>

<label for="marginConsignment">Margin to supplier</label>
<input style="margin-left: 5px;" id="margin" data-role="numerictextbox" data-bind="value: marginConsignment">
</div>

JavaScript :

function consign() {
var radiobtn = document.getElementById("yes3").value;
if(radiobtn == "y"){
$("#margin").prop("disabled", false);
} else if (radiobtn == "n"){
$("#margin").prop("disabled", true);
}
}

最佳答案

你可以试试这样的:

HTML

<div class="k-edit-label">
<label for="consignment">Consignment</label>
</div><div>
<input class="k-radio" id="yes3" name="consignment" type="radio" onClick="consign()" data-bind="checked:consignment">
<label class="k-radio-label" for="yes3">Yes</label>
<input class="k-radio" id="no3" onClick="consign()" name="consignment" type="radio" data-bind="checked:consignment">
<label class="k-radio-label" for="no3" style="margin-left: 30px; margin-right:20px;">No</label>

<label for="marginConsignment">Margin to supplier</label>
<input style="margin-left: 5px;" id="margin" data-role="numerictextbox" data-bind="value: marginConsignment">
</div>

JS

    function consign() {
document.getElementById("margin").disabled = document.getElementById("yes3").checked;
}

关于javascript - 禁用 numericTextBox onClick 单选按钮单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58929258/

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