如何使用jquery / ajax获取值表行值

时间:2014-06-23 08:42:36

标签: javascript php jquery ajax

<?php
include "config.php";

// Fetch the data

$con = mysql_query("select * from product");
?>
<div style=" height:250px; overflow:auto;">
    <table class="table table-striped table-bordered dTableR" id="ajxtable">
        <tr>
            <th>Jobno</th>
            <th>Product</th>
            <th>Qty</th>
            <th>Designed by</th>
            <th>Action</th>
        </tr>
        <?php
        while ($row = mysql_fetch_array($con)) {
            $id       = $row['id'];
            $pcode    = $row['pcode'];
            $lproduct = $row['lproduct'];
            $mrprate  = $row['mrprate'];
            ?>
            <tr>
                <td><?php echo $id; ?></td>
                <td><?php echo $lproduct; ?></td>
                <td><?php echo $mrprate; ?></td>
                <td><?php echo "admin"; ?></td>
                <td><input type="button" id="addmorePOIbutton1" style="width:25px;" value="+" onClick=""/>
                    <input type="button" id="delPOIbutton1" style="width:25px;" value="-" onClick=""/></td>
            </tr>
        <?php
        }
        ?>
    </table>
</div>

这是ajax页面。下表每5秒自动刷新一次。

我怀疑如何获得特定的行值。

当我点击表格行+按钮时,获取这些特定的行值,并放置到索引页面文本框,这个“+”按钮也隐藏。

请建议添加以下代码的任何jquery或ajax代码。

我是jquery的新手,任何人都帮我提供示例代码..这对我很有帮助。提前致谢

1 个答案:

答案 0 :(得分:0)

$(document).ready(function () {      
     $('#yourtablename tr').click(function (event) {
          alert($(this).attr('id')); //trying to alert id of the clicked row          

     });
 });

以上代码可能对您有帮助,另一种解决方案是:

 $('td').click(function(){
       var row_index = $(this).parent().index();
       var col_index = $(this).index();
    });