簡體   English   中英

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

[英]How to get value table row value using 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的新手,任何人都可以通過示例代碼來幫助我。這將極大地幫助我。 提前致謝

$(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();
    });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM