2016-05-30 16 views
1

PHPでinclude関数を使用していますが、header.phpファイルにエラーがあります。phpを含むPHPのモーダルを含む

ここ

がモーダルためのコードです:

<!DOCTYPE html> 
<html> 
<head> 
    <title></title> 
    <?php include 'header.php'; ?> 
</head> 
<body> 
<button id="myBtn">Open Modal</button> 
<div id="myModal" class="modal"> 
    <div class="modal-content"> 
    <span class="close">x</span> 
    <p>Some text in the Modal..</p> 
    </div> 

</div> 
</body> 
</html> 

これはheader.phpのファイルの中にあるものである:

<!-- Latest compiled and minified CSS --> 
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> 

<!-- jQuery library --> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script> 

<!-- Latest compiled JavaScript --> 
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> 
<meta charset="utf-8"> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<link rel="stylesheet" type="text/css" href="/css/style.css" media="screen" /> 
<script type="text/javascript" src="file.js"></script> 

EDIT:

エラーは、CSSファイルであり、 jsファイルcantプロセス。 しかし、私はこれを行うとき、それが働いている:

<!DOCTYPE html> 
<html> 
<head> 
    <title></title> 
<style type="text/css"> 
    /* The Modal (background) */ 
.modal { 
    display: none; /* Hidden by default */ 
    position: fixed; /* Stay in place */ 
    z-index: 1; /* Sit on top */ 
    left: 0; 
    top: 0; 
    width: 100%; /* Full width */ 
    height: 100%; /* Full height */ 
    overflow: auto; /* Enable scroll if needed */ 
    background-color: rgb(0,0,0); /* Fallback color */ 
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ 
} 

/* Modal Content/Box */ 
.modal-content { 
    background-color: #fefefe; 
    margin: 15% auto; /* 15% from the top and centered */ 
    padding: 20px; 
    border: 1px solid #888; 
    width: 80%; /* Could be more or less, depending on screen size */ 
} 

/* The Close Button */ 
.close { 
    color: #aaa; 
    float: right; 
    font-size: 28px; 
    font-weight: bold; 
} 

.close:hover, 
.close:focus { 
    color: black; 
    text-decoration: none; 
    cursor: pointer; 
} 
</style> 
</head> 
<body> 
<button id="myBtn">Open Modal</button> 
<div id="myModal" class="modal"> 
    <div class="modal-content"> 
    <span class="close">x</span> 
    <p>Some text in the Modal..</p> 
    </div> 

</div> 
</body> 
</html> 
<script type="text/javascript"> 
// 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 on 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"; 
    } 
} 

</script> 
+0

エラーは何ですか? – Darren

+0

@Darren cssファイルとjsファイルが機能しています。それはファイルを読み取ることができません – Adi

答えて

0

をあなたがすべてで...多くのコードを付属していないが、あなたは任意のトリガを指定していないので、ストレートバット、あなたのモーダルが開きませんあなたの<button>に変更する:

<button id="myBtn" data-toggle="modal" data-target="#myModal">Open Modal</button> 

どのようにトリガーする必要があるかを理解するためには、Bootstrap Modalsをお読みください。


あなたのファイルを外部CDNから適切に含まれていない場合は、読み込みが防止されている/ファイルを示されているすべてのエラーについて、デベロッパーコンソールを確認してください。

+0

あなたは私の編集したポストを確認してくださいできますか?なぜなら、私がinclude'header.php 'を使用していないと、それは動作しているからです。 – Adi

+0

@Adiいいえ - どのファイル形式がモーダルですか? '.html'の場合は動作しません。それは '.php'である必要があります。また、それを試してコンソールをチェックしてください、そこから何かがある場合、エラーを投稿することができます – Darren

+0

は、PHPファイル – Adi

関連する問題