如何避免选择具有相同值的2个单选按钮?

时间:2017-08-17 16:42:50

标签: javascript forms radio

我有一个表单,我有两组单选按钮,名称不同但值是共享的,所以我需要从第一组中选择一个收音机,一旦它从第二组中选择了收音机,无法选择相同的值,i。即它变得残疾......

<table>
<tr><th>Origin language</th><th>Target language</th></tr>
<tr><td>
<label><input type="radio" name="lang_or" value="de">German</label>
<label><input type="radio" name="lang_or" value="en">English</label>
<label><input type="radio" name="lang_or" value="ca">Catalan</label>
<label><input type="radio" name="lang_or" value="es">Spanish</label>
<label><input type="radio" name="lang_or" value="fr">French</label>
<label><input type="radio" name="lang_or" value="it">Italian</label>
<label><input type="radio" name="lang_or" value="pt">Portugues</label>
</td><td>
<label><input type="radio" name="lang_tg" value="de">German</label>
<label><input type="radio" name="lang_tg" value="en">English</label>
<label><input type="radio" name="lang_tg" value="ca">Catalan</label>
<label><input type="radio" name="lang_tg" value="es">Spanish</label>
<label><input type="radio" name="lang_tg" value="fr">French</label>
<label><input type="radio" name="lang_tg" value="it">Italian</label>
<label><input type="radio" name="lang_tg" value="pt">Portugues</label>
</td></tr>
</table> 

1 个答案:

答案 0 :(得分:2)

导入jQuery

<head>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
 </head>



  <script>
$( document ).ready(function() {

$('input[name=lang_or]').click(function(){

$('input[name=lang_tg]').prop("disabled",false);
$('input[name=lang_tg][value='+this.value).prop("disabled", "disabled");

});

});
</script>