根据选定的选项禁用单选按钮 [英] Disable radio button according to selected choice

查看:110
本文介绍了根据选定的选项禁用单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据选定的选项禁用html表单中的某个单选按钮,如果他在第一个单选按钮组中选择第一个选项,则将启用第二个单选按钮组中的2个选项,如果不是,则会禁用它们,这是我的代码:

I want to disable some radio button in a html form according to selected choices, if he select the first choice in the first radio button group the 2 choices in the second radio button group will be enabled, if not they will be disabled, here's my code:

<script language="javascript">
function RadioMeuble() {
    if (document.f.radio1[0].checked) {
        alert("Vous avez choisi la proposition " + document.f.radio1[0].value);
        document.f.radio2[0].disabled = false;
        document.f.radio2[1].disabled = false;
    } else {
        document.f.radio2[0].disabled = true;
        document.f.radio2[1].disabled = true;
    }
}
}
</script>
<input type="radio" name="radio1" value="L" id="radio1" onBlur="RadioMeuble()">á louer</label>
<br>
<label>
    <input type="radio" name="radio1" value="V" id="radio1">á vendre</label>
</p>
<p>Superficie
    <label for="textfield"></label>
    <input type="text" name="superficie" id="Superficie">en Km ²</p>
<p>Prix
    <label for="textfield2"></label>
    <input type="text" name="prix" id="Prix">en DT</p>
<p>Meublé
    <input type="radio" name="radio2" id="radio2" value="oui" disabled>Oui
    <input type="radio" name="radio2" id="radio2" value="non" disabled>
    <label for="radio2"></label>
    <label for="radio"></label>Non</p>

它不起作用。它有什么问题?

It doesn't work. What's wrong with it?

推荐答案

请勿使用onblur EventHandler。您应该使用onchange或onclick。

Don't use the onblur EventHandler. You should use onchange or onclick instead.

<input type="radio" name="radio1" value="L" id="radio1" onchange="RadioMeuble()">

<input type="radio" name="radio1" value="L" id="radio1" onclick="RadioMeuble()">

HTH,

- hennson

--hennson

这篇关于根据选定的选项禁用单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆