Javascript 禁用单选按钮上的文本框单击
我有两个单选按钮。 每个单选按钮有两个文本框 我只想做的是,如果单击第一个单选按钮,则应禁用包含文本框的其他单选按钮,反之亦然。示例: HTML 牛奶 干酪 Javascript var form=document.forms['myform']; form.group1[0]。onfocus=function{ form.text1.disabled=form.text2.disabled=false; form.text3.disabled=form.text4.disabled=true; } form.group1[1]。onfocus=function{ form.text1.disabled=form.text2.disabled=true; form.text3.disabled=form.text4.disabled=false; }Javascript 禁用单选按钮上的文本框单击,javascript,jquery,Javascript,Jquery,我有两个单选按钮。 每个单选按钮有两个文本框 我只想做的是,如果单击第一个单选按钮,则应禁用包含文本框的其他单选按钮,反之亦然。示例: HTML 牛奶 干酪 Javascript var form=document.forms['myform']; form.group1[0]。onfocus=function{ form.text1.disabled=form.text2.disabled=false; form.text3.disabled=form.text4.disabled=true;
您可以使用jqueryclick事件,并结合使用:checked过滤器 试试这把小提琴 这就是你的意思吗 HTML:
}请提供代码和/或JSFIDLE。实际上,现在我无法提供代码,因为代码在我的办公桌上。我在办公室里一直坚持这种情况。
<div>
<label for="radio1">
<input type="radio" name="test" value="radio1" /> Radio 1
</label>
<input type="text" name="for_radio1[]" class="radio1" disabled="true" />
<input type="text" name="for_radio1[]" class="radio1" disabled="true" />
<label for="radio2">
<input type="radio" name="test" value="radio2" /> Radio 2
</label>
<input type="text" name="for_radio2[]" class="radio2" disabled="true" />
<input type="text" name="for_radio2[]" class="radio2" disabled="true" />
</div>
$(document).ready(function(){
$('input[type=radio][name=test]').click(function(){
var related_class=$(this).val();
$('.'+related_class).prop('disabled',false);
$('input[type=radio][name=test]').not(':checked').each(function(){
var other_class=$(this).val();
$('.'+other_class).prop('disabled',true);
});
});
});
<input type="radio" id="textbox1" onclick="check(this.id)" checked="true" />
<textarea id="textarea1"></textarea>
<br>
<input type="radio" id="textbox2" onclick="check(this.id)"/>
<textarea id="textarea2" disabled="true"></textarea>
function check(id) {
var thistextbox = id.replace('box', 'area');
var othertextarea = 'textarea1';
if(id.slice(-1) == '1'){
othertextarea = 'textarea2';
}
var othertextbox = othertextarea.replace('area', 'box');
document.getElementById(id).checked = true;
document.getElementById(thistextbox).disabled = false;
document.getElementById(othertextarea).disabled = true;
document.getElementById(othertextbox).checked = false;