2017-03-20 12 views
0

私はこのモーダルスクリプトを動作させようとしていますが、何らかの理由で最初のdivだけが開き、phpと何か関係があります。 このコードはw3schoolsからコピーされ、編集されています。最初のモーダルを開くだけです

HTML/PHP:

<?php 
try 
{ 
$sQuery= "SELECT * FROM maillijst ORDER BY naam ASC"; 

$oStmt = $db->prepare($sQuery); 
$oStmt->execute(); 

while($rij = $oStmt->fetch(PDO::FETCH_ASSOC)) 
{ 
?> 

<!-- Modal content --> 
<div class="modal-content"> 
    <div class="modal-header"> 
    <span class="close">&times;</span> 
    <h2><?php echo($rij['naam']); ?></h2> 
    </div> 

    <div class="modal-body"> 
    <p><?php echo($rij['couponcode']); ?></p> 
    </div> 

    <div class="modal-footer"> 
    <h3><?php echo($rij['email']); ?></h3> 
    </div> 
</div> 

<?php 
} 
} 
catch(PDOException $e) 
{ 
    $sMsg = '<p> 
      Regelnummer: '.$e->getLine().'<br/> 
      Bestand: '.$e->GetFile().'<br/> 
      Foutmelding: '.$e->getMessage().' 
     </p>'; 

    trigger_error($sMsg); 
} 
$db=NULL; 
?> 

JAVASCRIPT:

<script> 
// Get the modal 
var modal = document.getElementById("myModal"); 

// Get the button that opens the modal 
var btn = document.getElementById("myBtn"); 

// Get the <span> element that closes the modal 
var span = document.getElementsByClassName("close")[0]; 

    // When the user clicks the button, open the modal 
btn.onclick = function() { 
    modal.style.display = "block"; 
    } 

// When the user clicks on <span> (x), close the modal 
span.onclick = function() { 
    modal.style.display = "none"; 
     } 

     // When the user clicks anywhere outside of the modal, close it 
      window.onclick = function(event) { 
      if (event.target == modal) { 
      modal.style.display = "none"; 
     } 
     } 
+0

なぜPHPは疑わしいですか?あなたはPHPなしでモーダルを使ってみましたか? –

+0

javacriptで参照しているhtml要素は表示されません。 –

+0

この質問に2番目のPHP部分を置いています... –

答えて

0

JavaScriptを使用してid = "myModal"の要素を操作しようとしています。 しかし、あなたのモーダルコンテンツにその要素が見つかりませんでした。 次のようなものがあります:

span.onclick = function() { 
$(this).closest('.modal-content').css('display', 'none'); 
} 
+0

私はspan.onclickを変更しようとしましたが、変更はしていないようです何か –

+0

@ E.dewildeも同様にコメントに返信することができます –

関連する問題