如何传递锚点标签中的单选按钮id


How to pass the radio button id in the anchor tag?

我有这样的记录列表

o 1 xxx yyy
o 2 xxx yyy
o 3 xxx yyy

如果我点击第一个记录单选按钮,则1的值传递到锚标签

    <?php foreach($model as $result) { ?>
        <tr>    
            <td>
                <input type="radio" name="pol_id" value="<?=$result['id']?>" />
                <?=$result['name']?>
            </td>
            <td><?=$result['country']?></td>
            <td><?=$result['state']?></td>
        </tr>
    <?php } ?>
    <tr>
        <td align="right">
            <a href="update?id=<?=$result['id']?>">Edit
        </td>
    </tr>

您需要使用javascript。

jQuery代码:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>$(function(){
  $('input:radio').change(function(){
    $('a').attr('href', 'update?id='+$(this).val()); // better if you add an id to anchor & then $('a#idofAnchor')
});
});</script>