我点击它时想要特定的单元格值

时间:2016-07-30 07:11:47

标签: javascript php jquery

<?php

    $con = mysql_connect('localhost','root','');
    $db = mysql_select_db("demo",$con);

?>

<!doctype html>
<html>
<head>
<title>Demo</title>
<!--JAVASCRIPT -->
<script  src="http://code.jquery.com/jquery-1.9.1.min.js" ></script>     
<script>
    $(document).ready(function(){
        $("#myTable td").click(function() {     

            var column_num = parseInt( $(this).index() ) + 1;
            var row_num = parseInt( $(this).parent().index() )+1;    

            //$("#result").html( "Row_num =" + row_num + "  ,  Column_num ="+ column_num );  
            alert(row_num); 
        });
    });
</script>
</head>
<body>
    <!--<div id="result"> </div>-->
    <table id="myTable" border="1" style="border-collapse: collapse;" cellpadding="8">
        <tr>
            <th>Name</th>
            <th>Qty</th>
            <th>Amount</th>
            <th>Total</th>
        </tr>

            <?php
                $sQ = "select * from tbl_demo";
                $eQ = mysql_query($sQ);
                while($fQ=mysql_fetch_array($eQ))
                    {
                        $name = $fQ['Name'];
                        $qty = $fQ['Qty'];
                        $amt = $fQ['Amount'];
                        //$total
                        $total = $fQ['Total'];
            ?>

        <tr>
            <td><input type="text" name="name" value="<?php echo $name; ?>" onchange="add($qty,$amt)"/> </td>
            <td><input type="number" name="name" value="<?php echo $qty; ?>"/></td>
            <td><input type="number" name="name" value="<?php echo $amt; ?>"/></td>
            <td><input type="number" name="name" value="<?php echo $total; ?>"/></td>
        </tr>
        <?php
            }
        ?>
        <tr>
            <td colspan="3" style="padding-left:400px"> Total </td>
            <td class="navigateTest"> <input type="number" name="name" value=""/> </td>
        </tr>
        <tr>
            <td colspan="4" class="navigateTest"> <input type="button" name="submit" id="submit" value="Submit"/> </td>
        </tr>
    </table>
</body>
</html>

这是我的代码。我得到特定行nd列的索引值bt我找不到那个单元格的值..我试图解决那个问题但是我无法理解我发现的代码......那是不同的方法?

我如何获得特定细胞的数据?????

plz将我改正方向......

0 个答案:

没有答案