0

ajaxを使用してページのdivをリロードすると機能しますが、スクリプトをリロードしようとすると機能しません。私のjavascriptはデータベースから動的であり、divも動的です。これが私のコードです:

        <ul id="classes">
            <?php
            $email = 'thomas990428@me.com_classes';

            $result = mysqli_query($con,"SELECT * FROM `$email` ORDER BY period"); if (!$result) echo mysqli_error(); else // ok, do your thing.

            $classcount = 1;

            while($row = mysqli_fetch_array($result))
              {

              $period = $row['period'];
              $teacher = $row['teacher'];
              $subject = $row['subject'];
              $subjecto = strtolower($subject);
              $subjecto = str_replace(' ', '', $subjecto);
              $grade = $row['grade'];

              echo "<li id='button" . $classcount . "' class='button' onclick='" . $subjecto . "(),homework" . $classcount . "()'><div class='deletebutton' onclick='deleteclass" . $subjecto . "()'>X</div><span class='course'>" . $classcount . ". " . $subject . "</span></li>\n";

              $classcount += 1;

              }

            ?>
    <script>

        <?php
        $email = 'thomas990428@me.com_classes';

        $result = mysqli_query($con,"SELECT * FROM `$email`");

        while($row = mysqli_fetch_array($result))
          {

          $period = $row['period'];
          $teacher = $row['teacher'];
          $subject = $row['subject'];
          $subjecto = strtolower($subject);
          $subjecto = str_replace(' ', '', $subjecto);
          $grade = $row['grade'];

          echo "function deleteclass" . $subjecto . "() { \n";
          echo "var hi = confirm('Are you absolutely sure you want to permantly delete this class? This cannot be undone.'); \n";
          echo "if (hi==true) \n";
          echo "{ \n";
          echo "document.getElementById('hiddenframe').src='deleteclass.php?class=".$subjecto."';";
          echo "closeedit();";
          echo "refreshclasses();";
          echo "} \n";
          echo "else \n";
          echo "{} \n";
          echo "} \n";

          }

        ?>


    </script>
        </ul>
        <iframe id="hiddenframe"></iframe>

つまり、基本的にはulを更新しますが、スクリプトは更新しません。必要なことを行うために、両方を更新する必要があります。何か案は?ありがとう!

4

1 に答える 1

0

最初にコメントを読んで、そして...

コードを調べて、代わりにこれを実行してみませんか?

function deleteClass(subjecto, period, teacher, ...)

onclick='deleteClass(" . $subjecto . ", " . $period. ", " . $teacher. ")'

今のところそれを機能させたいだけなら、これを行うことができます:

交換:

<div class='deletebutton' onclick='deleteclass" . $subjecto . "()'>X</div>

に:

<div class='deletebutton' onclick='deleteclass(" . $subjecto . ")'>X</div>

そして、echo<script>の部分全体を次のように置き換えます。

function deleteclass(subjecto){
    var hi = confirm('Are you absolutely sure you want to permantly delete this class? This cannot be undone.');
    if (hi==true)
    {
        document.getElementById('hiddenframe').src='deleteclass.php?class='+subjecto;
        closeedit();
        refreshclasses();
    }
}
</script>
于 2013-03-10T08:51:42.260 に答える