Javascript jquery中的自动选择对应无线电

Javascript jquery中的自动选择对应无线电,javascript,jquery,radio-button,Javascript,Jquery,Radio Button,我在一个div中使用了动态收音机,就像这里一样,收音机的名称是动态的,也有价值: <input type="radio" name="first[1]" value="1" /> <input type="radio" name="first[2]" value="2" /> <input type="radio" name="first[3]" value="3" /> And the second div I have which have these

我在一个div中使用了动态收音机,就像这里一样,收音机的名称是动态的,也有价值:

<input type="radio" name="first[1]" value="1" />
<input type="radio" name="first[2]" value="2" />
<input type="radio" name="first[3]" value="3" />


And the second div I have which have these radios : 

<input type="radio" name="second[1]" value="1" />
<input type="radio" name="second[2]" value="2" />
<input type="radio" name="second[3]" value="3" />

我的第二个部门有这些收音机:
我的问题是,如果我选中(是)div first单选按钮 然后,选择自动div第二收音机。这就像两个电台一样 共同检查是否存在这两种情况

我试图得到第一个div的值,但是这里我没有得到值

<script type="text/javascript">
$(document).ready(function(){
alert('ok');
$('input:radio').on('click',function() { 
var obj=$('input[name="first"]:checked').val();
alert(obj);
});
});
</script>


Can any one please help me related this?

$(文档).ready(函数(){
警报(“正常”);
$('input:radio')。在('click',function(){
var obj=$('input[name=“first”]:checked').val();
警报(obj);
});
});
有谁能帮我解释一下吗?
提供一些额外的信息,如:


<script type="text/javascript">
$(document).ready(function(){
    var first = $('input[name^=first]');
    var second = $('input[name^=second]');
    first.change(function(){
        var index = $(this).index();
        if(this.checked){
            second.eq(index).prop('checked', true);
        }
});
</script>
$(文档).ready(函数(){ var first=$('input[name^=first]'); var second=$('input[name^=second]'); 第一,改变(函数(){ var index=$(this.index(); 如果(选中此项){ 第二个.eq(index).prop('checked',true); } });
//在此处添加您的javascript
$(函数(){
$('input[name^=“first”],input[name^=“second”]”)。在('change',function()上{
设i=$(this.index();
$('input[name^=“first”]”)。每个(函数(j){
$(this.prop('checked',i==j);
});
$('input[name^=“second”]”)。每个(函数(j){
$(this.prop('checked',i==j);
});
});
});

A.
B
C
AA
BB
科科斯群岛

在您的代码中,当您添加警报时,它会显示出来,但在我的情况下,警报不起作用。为什么…您有这一行
$('input[name=“first”]:checked').val();
但是您的输入元素中没有一个名称等于first…您有一个名称等于“first[1]”,另一个名称等于“first[2]”,另一个名称等于“first”[3] ,因此,使用选择器'input[name=“first”:checked'这不会带来任何东西,使用他使用的选择器:'input[name^=“first”查找在itUr代码中具有“first”名称的任何输入在我的情况下都不起作用…查看我更新的问题有什么解决方案吗???