jquery - 使用 jquery 获取表中某一行的某些属性

标签 jquery mysql

我有一个像这样的 html 表格:

<table class="table table-bordered table-striped table-condensed" id="table1">
<thead>
    <tr>
        <th>No.  </th>
        <th>No Request</th>
        <th>Username</th>
        <th>Start Time</th>
        <th>Complaint</th>                                            
        <th>Estimation</th>                                            
        <th>Action</th>
    </tr>
</thead>   
<tbody>
    <tr>
        <td class="center">1.  </td>

        <td class="sorting1" id='no_request' data-id-reseh="001">TMS/IT/04/001</td>

        <td class="center">Erika</td>

        <td class="center">06-04-2015, 18:26 </td>

        <td class="center" id="description">Erika yang minta</td>                                            

        <td class="center">06-04-2015, 18:56 </td>                                            

        <!-- Action-action -->
        <td  class="center">
            <a class="btn btn-info" id="btn-edit" name="edit"  data-toggle="modal" data-target="#myModal" role="button" title="Beri Keterangan Request No. 1">
                <i class="halflings-icon white edit"></i>
                Comment
            </a>

            <a class="btn btn-warning" >
                <i class="halflings-icon white arrow-up" id="print" email="tmsmkt1@tresnamuda.co.id"></i>
                Approve 
            </a>         
        </td>
    </tr>

    <tr>
        <td class="center">2.  </td>

        <td class="sorting1" id='no_request' data-id-reseh="002">TMS/IT/04/002</td>

        <td class="center">Ullinawati</td>

        <td class="center">06-04-2015, 18:27 </td>

        <td class="center" id="description">Ullie yang minta</td>                                            

        <td class="center">06-04-2015, 18:57 </td>                                            

        <td  class="center">
            <a class="btn btn-info" id="btn-edit" name="edit"  data-toggle="modal" data-target="#myModal" role="button" title="Beri Keterangan Request No. 2">
                <i class="halflings-icon white edit"></i>
                Comment
            </a>

            <a class="btn btn-warning" >
                <i class="halflings-icon white arrow-up" id="print" email="ullie@tresnamuda.co.id"></i>
                Approve 
            </a>         
        </td>
    </tr>

</tbody>

我的问题是,我可以根据表的行 grep 属性“email”吗? 所以可以说,第一行是=“tmsmkt1@tresnamuda.co.id”,第二行是=“ullie@tresnamuda.co.id”。 我编写了一些像这样的 jquery 代码:

  $(document).ready(function() {
    $(".btn-warning").click(function(e) {
        e.preventDefault();

        var $this = $(this);
        var idStr = $this.attr("email");

        console.log($this.attr('email')); // Failed
        console.log(idStr); // failed too

    });

感谢您的帮助...

最佳答案

由于 email 属性附加在 i 元素上,该元素是 btn-warning 的子元素,因此需要使用 查找()

$(".btn-warning").click(function(e) {
    e.preventDefault();
    console.log($(this).find("i").attr('email')); 
});

find() 将获取子元素。 Fiddle

关于jquery - 使用 jquery 获取表中某一行的某些属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29513796/

相关文章:

php - 更快/更轻松地查询此结果数组

java - mysql jdbc连接没有错误但在网页上不起作用

jQuery Mobile 加载 ui-icon-alt

javascript - 如何使用 FLOT 图表保存图例

jquery - 如果调整图像大小,Jcrop 会出现问题 - Jquery

php - 将新表格行推送到浏览器的最佳方式是什么?

javascript - 如果在服务器上修改,则重新加载页面

javascript - 如何使用 javascript 或 jquery 删除选择上的名称并在文本区域上添加名称?

mysql - Javascript、AJAX获取MySQL内容到div中

php - 选择与日期选择器中相同的日期