繁体   English   中英

用于禁用或启用单选按钮的Javascript

[英]Javascript to disable or enable radio buttons

我正在尝试做一些比这更复杂的事情,但我把它分解并扔进了JSFIDDLE ,我仍然无法让它工作。

有什么建议么?

的jsfiddle

HTML:

<label for="service-type">Value</label>
<select id="service-type" onChange="hamburger()">
  <option>0</option>
  <option>1</option>
  <option>2</option>
  <option>3</option>
</select>
<label for="receiptNo">No</label>
<input type="radio" name="receipt" id="receiptNo">
<label for="receiptYes">Yes</label>
<input type="radio" name="receipt" id="receiptYes">

使用Javascript:

var e = document.getElementById("service-type");
var ServiceUser = e.options[e.selectedIndex].text;

function hamburger() {
   if (ServiceUser.value === "2") {
      document.getElementById("receiptNo").disabled = true;
      document.getElementById("receiptYes").checked = true; 
     } 
}

像这样发送函数调用者的详细信息

<select id="service-type" onchange="hamburger(this)">
    <option>0</option>
    <option>1</option>
    <option>2</option>
    <option>3</option>
</select>
<input type="radio" name="receipt" id="receiptNo">
<input type="radio" name="receipt" id="receiptYes">

用javascript完成它

<script type="text/javascript">
    function hamburger(sender) { // sender here has all details of dropdown
        if (sender.value === "2") {
            document.getElementById("receiptNo").disabled = true;
            document.getElementById("receiptYes").checked = true;
        }
    }
</script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM