День добрый. Пытаюсь в строках таблицы циклом вывести модальные окна. Не могу победить баг, при котором 1-е модальное окно автоматически вываливается на страничку.
Код (php + js) ниже. Скрин проблемы:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<?
require_once 'functions.php';
error_reporting(E_ALL);
ini_set("display_errors", 1);
$index = [];
// echo"<pre>";
echo "<table><td>";
for ($i=0; $i < 10; $i++) {
echo "<tr>";
$index[$i] = $i+1;
?>
<button type="button" class="btn btn-info btn-lg" id="myBtn<? echo $index[$i]; ?>">Open Modal</button>
<div class="container">
<!-- Modal -->
<div class="modal fade" id="myModal<? echo $index[$i]; ?>" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<table>
<thead>
</thead>
<tbody>
Содержимое модального окна № <? echo $i+1; ?>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$("#myBtn<? echo $index[$i]; ?>").click(function(){
$("#myModal<? echo $index[$i]; ?>").modal();
});
});
</script>
<?
echo "</tr>";
}
echo "</td></table>";
?>
</body>
</html>
Заранее спасибо.