jquery表编辑 - 无法设置变量

时间:2012-09-05 00:57:24

标签: php jquery

更新:想出来......首先需要在DOM中升级。

 var map_id = $(this).parent().find(".map_id").attr('value');
 var corrected_isin= $(this).parent().find(".corrected_isin").val();
 var corrected_cusip = $(this).parent().find(".corrected_cusip").val();
 var corrected_ticker = $(this).parent().find(".corrected_ticker").val();

我在让jquery为我工作方面遇到了很多麻烦......我正在尝试更新数据表。我所有的更新代码都运行正常,但无论出于何种原因,我试图用jquery设置的变量都是不确定的。下面的代码不是设置变量。当我对变量进行硬编码时,它可以正常工作。我也试过使用ID代替类无济于事。请帮忙!

谢谢你,大卫

        var map_id = $(this).children(".map_id").attr('value');
        var corrected_isin = $(this).children(".corrected_isin").val();
        var corrected_cusip = $(this).children(".corrected_cusip").val();   
        var corrected_ticker = $(this).children(".corrected_ticker").val();

完整代码:

<html>
<head>
<title>ISIN Editor</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("form").submit(function() {
        var map_id = $(this).children(".map_id").attr('value');
        var corrected_isin = $(this).children(".corrected_isin").val();
        var corrected_cusip = $(this).children(".corrected_cusip").val();   
        var corrected_ticker = $(this).children(".corrected_ticker").val();

        $.ajax({
            type: "GET",
            url: "aj/table_edit_ajax.php",
            data: {corrected_isin: corrected_isin, corrected_cusip: corrected_cusip, corrected_ticker:  corrected_ticker,  map_id: map_id},
            cache: false,
            success: function(){
                alert(map_id + " " + corrected_isin + " " + corrected_cusip + " " + corrected_ticker );
            }
        });
       return false;
   });
});
</script>
</head>
<body>

<?php

include("aj/db.php");
$query = "SELECT map_id, ria_crd, position_cusip, position_ticker, position_description, position_first_date, position_last_date, map_corrected_isin, map_corrected_cusip, map_corrected_ticker FROM map_to_isin WHERE map_correct_status IN (2,5)";

$result = mysql_query($query,$bd);

?>
    <table>
    <tr>
    <th>map_id</th>
    <th>RIA CRD</th>
    <th>Reported CUSIP</th>
    <th>Reported Ticker</th>
    <th>Reported Description</th>
    <th>Date Range</th>
    <th>New isin</th>
    <th>New CUSIP</th>
    <th>New Ticker</th>
    <th>Submit Change</th>
    </tr>

<?php
$row_num = 1;
while($row = mysql_fetch_array($result))
  {

    echo "<tr"; 
    if($row_num%2) { 
        echo " bgcolor='pink'";
    }; 
    echo ">"; ?>

    <form id="form<? echo $row['map_id'] ?>"> 
    <input type="hidden" name="map_id" class="map_id" value="<? echo $row['map_id'] ?>"/>
    <td><? echo $row['map_id'] ?></td>
    <td><? echo $row['ria_crd'] ?></td>
    <td><? echo $row['position_cusip'] ?></td>
    <td><? echo $row['position_ticker'] ?></td> 
    <td><? echo $row['position_description'] ?></td>
    <td><? echo $row['position_first_date'] . " -> " . $row['position_last_date'] ?></td>
    <td><input type="text" name="corrected_isin" class="corrected_isin" value="<? echo $row['map_corrected_isin'] ?>"/></td>
    <td><input type="text" name="corrected_cusip" class="corrected_cusip" value="<? echo $row['map_corrected_cusip'] ?>"/></td>
    <td><input type="text" name="corrected_ticker" class="corrected_ticker" value="<? echo $row['map_corrected_ticker'] ?>"/></td>
    <td><input type='submit' value='Update' /></td>
    </form>
    </tr>
    <?php
    $row_num ++;
  }
echo "</table>";

mysql_close($bd);

?>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

尝试做:

 var map_id = $(this).parent().find(".map_id").val();
    var corrected_isin = $(this).parent().find(".corrected_isin").val();
    var corrected_cusip = $(this).parent().find(".corrected_cusip").val();   
    var corrected_ticker = $(this).parent().find(".corrected_ticker").val();