0
단일 페이지 응용 프로그램 웹 사이트에서 PHP 페이지 내에있는 모달 창을 구현하려고하는데 모달 창을 작동시키지 못했습니다. .각도/PHP 내의 단일 창 단일 페이지 응용 프로그램이 작동하지 않습니다.
비록 내가 내 함수를 저장하고있는 .js 파일을 가지고 있긴하지만 PHP 페이지 내에서 모달 창을 사용하려고하는 javascript가 있습니다. .js 파일에 모든 함수를 넣길 원하지만이 방법으로는 작동하지 않습니다.
PHP의 페이지
이을 index.php되지 않지만, 모달 창
의 초기 페이지로드
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<img id="popup_img" src="#">
</div>
</div>
<div id="screenings">
<?php
$db = mysqli_connect("localhost", "root", "", "data");
$sql = "SELECT * FROM screenings";
$result = mysqli_query($db, $sql);
while ($row = mysqli_fetch_array($result)){
echo "<div id='img_div'>";
echo "<img id='img_screenings' class='modal_img' src='images/".$row['image']."' >";
//echo "<p>" .$row['text']."</p>";
echo "</div>";
}
?>
</div>
<script>
// Get the modal
var modal = document.getElementById('myModal');
// Get the button that opens the modal
//var btn = document.getElementsByClassName("modal_img");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
$("img").on("click", function() {
var source = ($(this).attr("src"));
//alert(source);
//$('#modal_popup').text(source);
$('#popup_img').prop('src', this.src);
});
// When the user clicks the button, open the modal
document.getElementById("img_screenings").onclick = function(){
modal.style.display = "block";
alert("hello");
}
// 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>
</body>
CSS의 후라고합니다 이 부분에 문제가 있다고 생각하지 않습니다.
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
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 */
text-align: center;
}
/* Modal Content */
.modal-content {
background-color: black;
position: relative;
margin: auto;
padding: 50px 40px 50px 50px;
display: inline-block;
}
/* The Close Button */
.close {
color: #aaaaaa;
float: right;
position: relative;
left: 20px;
bottom: 35px;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #FFFFFF;
text-decoration: none;
cursor: pointer;
}
.modal_img{
cursor: pointer;
}
현재로서는 브라우저 콘솔에 오류가 표시되지 않지만 모달 창이 표시되지 않습니다.
흠, 그럴 것 같지 않았습니다. 나는이 다른 모달 윈도우 코드를 다른 곳에서 사용하고 있지만,이 PHP 페이지에 넣으면 그것을 깨뜨린 것 같다. – rpivovar