单击单选按钮时禁用文本框
我有两个单选按钮。 每个单选按钮有两个TextBox我只想点击第一个单选按钮,然后禁用包含文本框的其他单选按钮,反之亦然。
您可以使用jquery click事件,结合:checked filter
尝试这个小提琴http://jsfiddle.net/8NynQ/
这是js
$(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); }); }); });
例:
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; }
的jsfiddle
你是这个意思吗?
HTML:
使用Javascript:
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;
}