2016-05-30 55 views
1

我想在包含函数的PHP中使用模态,但是我猜想header.php文件有错误。modal在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> 

编辑:

的错误是CSS文件和js文件不能处理。 但是当我这样做,它的工作:

<!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