使用jquery获取单个记录

时间:2016-04-30 07:31:29

标签: javascript jquery

在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'和'user_email'的单一时间值的结果

你能建议我吗?

感谢。

2 个答案:

答案 0 :(得分:1)

像这样在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);
});

答案 1 :(得分:0)

将类添加到电子邮件和标题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)
    });
相关问题