【问题标题】:How to pass the radio button id in the anchor tag? [duplicate]如何在锚标签中传递单选按钮 id? [复制]
【发布时间】:2014-10-20 14:16:01
【问题描述】:

我有这样的记录列表

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来做到这一点。
  • 请显示您渲染的 HTML,PHP 在这里无关紧要,更难为您提供帮助。

标签: javascript php


【解决方案1】:

您需要为此使用 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>

【讨论】:

  • 如果对单个单选按钮有更多操作意味着锄头我可以提供链接...例如:选择记录的一个单选按钮,我必须执行编辑/删除/查看... .
  • 发布与该问题相关的问题,如果需要帮助,请在此处分享网址。
  • 我通过给出Edit/Delete/View的id得到了答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-05
  • 1970-01-01
  • 2012-10-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多