0

私は動的な JavaScript コードの一部に取り組んできました。

$(document).ready(function() {
<?php 
    $sql = "SELECT * from pm_schedule";
    $result = $pdo->query($sql);
    foreach ($result as $row) 
        {
        echo 
            "$('#updatebtn".$row['id']."').click(function() {
             $('#result".$row['id']."').show('slow').delay(4000).hide('slow')
        $.post('process.php', $('#updateform".$row['id']."').serialize(), 
            });";
        }
?>
});

サーバーで実行すると、次のように展開されます。

$(document).ready(function () {

    $('#updatebtn1').click(function () {
        $('#result1').show('slow').delay(4000).hide('slow')
        $.post('process.php', $('#updateform1').serialize(),
        });

    $('#updatebtn2').click(function () {
        $('#result2').show('slow').delay(4000).hide('slow')
        $.post('process.php', $('#updateform2').serialize(),
        });

    $('#updatebtn3').click(function () {
        $('#result3').show('slow').delay(4000).hide('slow')
        $.post('process.php', $('#updateform3').serialize(),
        });

    $('#updatebtn4').click(function () {
        $('#result4').show('slow').delay(4000).hide('slow')
        $.post('process.php', $('#updateform4').serialize(),
        });

    $('#updatebtn5').click(function () {
        $('#result5').show('slow').delay(4000).hide('slow')
        $.post('process.php', $('#updateform5').serialize(),
        });
    });

Google Chrome は、上記のコードに対してキャッチされていない構文エラーを返し続けます - 理由について何か考えはありますか? 2 番目のコード ブロックではなく、最初のコード ブロックを編集する必要があることに注意してください。

4

2 に答える 2

4

,ここで最後のカンマを$('#updateform".$row['id']."').serialize(),<-- に置き換えます)

于 2013-02-06T23:58:23.210 に答える
0

後にセミコロンがなく、後hide('slow')にカンマが追加されていますserialize()

于 2013-02-07T00:01:10.570 に答える