单击时,我希望在单选按钮中添加if / else if
这是我的密码
<input type="radio" name="myradio" value="Radio 1" >
<label>Radio 1</label>
<input type="radio" name="mysubradio" value="Radio Sub 1" >
<label>Radio Sub 1</label>
<input type="radio" name="mysubradio" value="Radio Sub 2" >
<label>Radio Sub 2</label>
<br/><br/>
<input type="radio" name="myradio" value="Radio 2" >
<label>Radio 2</label> <br/><br/>
<input type="radio" name="myradio" value="Radio 3" >
<label>Radio 3</label>
<input name="more" placeholder="more" maxlength="50" type="text" >
您可以使用这里 Js Fiddle测试代码
帮助我,谢谢:)
发布于 2015-03-09 12:58:02
为了方便起见,我使用了jQuery,但这不是学习JavaScript基础知识的最佳方法。因此,请使用此解决方案作为演示,以了解您可以使用JavaScript & jQuery做什么,但是当您开始学习它时,只从JavaScript开始。
为了实现前面提到的逻辑,您可以这样做:
$('input').click(function() {
// Will be equal to the value of the selected radio
var myradio = $('input[name="myradio"]:checked').val();
if (myradio === 'Radio 1')
{
// Enable subradios
$('input[name="mysubradio"]').prop('disabled', false);
// Disable textbox
$('input[name="more"]').prop('disabled', true);
}
else if (myradio === 'Radio 2')
{
// Disable subradios
$('input[name="mysubradio"]').prop('disabled', true);
// Disable textbox
$('input[name="more"]').prop('disabled', true);
}
else if (myradio === 'Radio 3')
{
// Disable subradios
$('input[name="mysubradio"]').prop('disabled', true);
// Enable textbox
$('input[name="more"]').prop('disabled', false);
}
});
我更新了你的JSFiddle 这里。现在,我建议您开始使用教程学习教程,然后发现jQuery,以便理解我给您的代码。
干杯
https://stackoverflow.com/questions/28940199
复制相似问题