使用jquery获取单个记录

get single records using jquery

本文关键字:记录 单个 获取 jquery 使用      更新时间:2023-09-26

在php的Foreach循环中,我只获得点击事件'product_title'和'email'。代码如下。

foreach($abs_records as $abs)
{
    <tr>
        <td><input type="checkbox" name="case[]" class="case" ></td>
        <td><?php echo $abs['product_id']; ?></td>
        <td><?php echo $abs['product_title']; ?></td>
        <td><?php echo $abs['user_email']; ?></td>
        <td class="send_mail_btn"><a href="javascript:void(0)" >Send</a></td>
    </tr><?php
} ?>    

使用Jquery单击"发送",我将获得"Product_title"answers"user_email"的Single Time值的结果

你能推荐我吗?

谢谢。

向td元素添加一个类,如下所示:

<tr>
    <td><input type="checkbox" name="case[]" class="case" ></td>
    <td><?php echo $abs['product_id']; ?></td>
    <td class="title"><?php echo $abs['product_title']; ?></td>
    <td class="email"><?php echo $abs['user_email']; ?></td>
    <td class="send_mail_btn"><a href="javascript:void(0)" >Send</a></td>
</tr>

然后你可以在jQuery:中找到相关的值

$(document).on('click', '.send_mail_btn', function() {
  var title = $(this).siblings('.title').html();
  var email = $(this).siblings('.email').html();
  console.log("Title: " + title);
  console.log("Email: " + email);
});

将类添加到电子邮件和标题td,还添加类发送锚标签+在jquery中添加点击事件以获得值

  foreach($abs_records as $abs)
    {
        <tr>
            <td><input type="checkbox" name="case[]" class="case" ></td>
            <td><?php echo $abs['product_id']; ?></td>
            <td class="title"><?php echo $abs['product_title']; ?></td>
            <td class="email"><?php echo $abs['user_email']; ?></td>
            <td class="send_mail_btn"><a class="send-link" href="javascript:void(0)" >Send</a></td>
        </tr><?php
    } ?>   

    Jquery:
    $(".send-link").click(function() {
    var title = $(this).parent("tr").find(".title").text();
    var email = $(this).parent("tr").find(".email").text();
    alert(title+ " -- "+email)
    });