javascript - jQuery 函数仅在第一行运行

标签 javascript php jquery mysql wordpress

我已经将所有值从数据库提取到表中

foreach ( $result as $print )   {
    ?>
<form method="post">
    <tr>
        <td><a href="#" id="edit-btn">Edit</a></td>
</tr>
<tr>
<div class="edit-box1">
   <input id="idd" type="text" readonly="readonly" value="<?php echo $idd; ?>" name="status111">
   <input type="submit" value="GO" name="edit-go">
</div>
</tr>
</form>
}

这是 jQuery 代码:

   jQuery(document).ready(
    function() {
        jQuery("#edit-btn").click(function() {
            jQuery("#idd").prop("readonly", false);
        });
    });

问题是我有 20 行,而我的编辑按钮只在第一行运行。

如何让 jQuery 在所有行上运行?

最佳答案

这将是您的 HTML

$cnt=0;
foreach ( $result as $print )   {
?>
    <form method="post">
        <tr>
            <td><a href="#" class="edit-button" id='<?php echo $cnt;?>'>Edit</a></td>
        </tr>
        <tr>
        <div class="edit-box1">
            <input id="idd<?php echo $cnt;?>" type="text"  readonly="readonly" value="<?php echo $idd; ?>" name="status111">
            <input type="submit" value="GO" name="edit-go">
            <?php $cnt++; ?>
        </div>
        </tr>
     </form>
}

这将是您的 jquery 代码

<script>

   jQuery(document).ready(
       function() {
           jQuery(".edit-button").click(function() {
           jQuery("#idd"+$(this).attr("id")).prop("readonly", false);
       });
   });
</script>

希望这一定会奏效。

关于javascript - jQuery 函数仅在第一行运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39053976/

相关文章:

javascript - 通过 POST axios vue 传递多个参数

javascript - 在获取 <td> 值方面需要帮助

php - Paypal 网络支付标准 - 退款。它们可以通过 Api 完成吗?

jQuery serialize() 不适用于 IE 中的 Ajax 加载对话

javascript - 在 jQuery 悬停时移动 div 背景位置

javascript - 如何将窗口滚动与充满偏移顶部的数组进行比较?

javascript - 单击按钮一次后禁用按钮

javascript - 无论如何,有没有要更改错误代码 “TypeError: a is undefined”?

php - 即使页面存在,mod_rewrite 中的最后一条规则也会返回 404

javascript - 是否有任何事件可以检测textarea的值变化?