doujiebo9849 2016-05-24 06:44
浏览 24

如何在Javascript代码中声明我的模态

Actually i want to set the Modal on the box-click so i put the onclick tag in the box tag but after that my modal is not appear... Actually i passed the unique-Id for the individual box and that's work's fine but the Modal is not appear.....So please help me

   <?php

 include("connect.php");
$query="SELECT * FROM `orders`";
$filter_Result=mysqli_query($con,$query);

$count=0;
while($row = mysqli_fetch_array($filter_Result)){
 $count++;
 $boxid = $count;

        echo "<div class='block'>"; 



 echo "<div class='boxed' id=$boxid onclick='myFunction($boxid)'>";
 "<button id='$boxid'>Open Modal</button>";

 "<div id='$boxid' class='modal'>";

 "<div class='modal-content'>";
 "<span class='close'>x</span>";
 "<p>Some text in the Modal..</p>";
  "</div>";

  "</div>";
   echo "<div id='container'>";


  echo "<td>" . $row['id'] . "</td>" ."<br>"; 
   echo "<td>" . $row['status'] . "</td>"."<br>";
  echo "<td>" . $row['created_date'] . "</td>"."<br>";
  echo "<td>" . $row['uid'] . "</td>"."<br>"."<br>"."<br>"."<br>";

  echo "</div>";


  echo "</div>";


  echo "</div>";


 }

  ?>
 <script>
  function myFunction(id) {
  //modal = document.getElementById($id);
    //window.alert(modal);

  // Get the button that opens the modal
   //var btn = document.getElementById("myBtn");
    window.alert(id);
    document.getElementById(id).innerHTML = Date();

    }

 </script>
  • 写回答

2条回答 默认 最新

  • douqian6315 2016-05-24 06:53
    关注

    Replace this code:

    <?php
    
    include("connect.php");
    $query="SELECT * FROM `orders`";
    $filter_Result=mysqli_query($con,$query);
    
    $count=0;
    while($row = mysqli_fetch_array($filter_Result)){
     $count++;
     $boxid = $count;
    
        echo "<div class='block'>"; 
    
    
    
     echo "<div class='boxed'>";
     "<button onclick='myFunction($boxid)'>Open Modal</button>";
    
     "<div id='$boxid' class='modal'>";
    
     "<div class='modal-content'>";
     "<span class='close'>x</span>";
     "<p>Some text in the Modal..</p>";
      "</div>";
    
      "</div>";
       echo "<div id='container'>";
    
    
      echo "<td>" . $row['id'] . "</td>" ."<br>"; 
       echo "<td>" . $row['status'] . "</td>"."<br>";
      echo "<td>" . $row['created_date'] . "</td>"."<br>";
      echo "<td>" . $row['uid'] . "</td>"."<br>"."<br>"."<br>"."<br>";
    
      echo "</div>";
    
    
      echo "</div>";
    
    
      echo "</div>";
    
    
     }
    
      ?>
     <script>
      function myFunction(id) {
          modal = document.getElementById($id);
          window.alert(modal);
      }
     </script>
    
    评论

报告相同问题?