此代码将显示从1991年到2100年的leap年和非leap年,我试图将table One换成leap年,而在非leap年中,我尝试了一个table年,但我失败了。
如何以表格格式或网格系统中将其带入?这是用于学术研究。
<!DOCTYPE html>
<html>
<head>
<title>Leap Year</title>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<?php
function isLeap($year) {
return ((($year % 4) == 0) && ((($year % 100) != 0)));
}
for($year=1991; $year<=2100; $year++)
{
If (isLeap($year))
{
$leap="$year : LEAP YEAR <br/>";
//echo "<div class='col-sm-12'>" . $leap . "</div>";
echo $leap;
}
else
{
$nonLeap="$year : Not leap year <br/>";
//echo "<div class='col-sm-6'>" . $nonLeap ."</div>";
echo $nonLeap;
}
}
?>
</body>
</html>
您的isleap函数是错误的。您也可以参考此帖子。
function isLeap($year) {
return ((($year % 4) == 0) && ((($year % 100) != 0) || (($year % 400) == 0)));
}
for($year=1991; $year<=2100; $year++)
{
if (isLeap($year))
{
$leaps[] = $year;
}
else
{
$nonLeaps[] = $year;
}
}
echo '<table><tr>';
foreach($leaps as $y)
{
echo '<td>' . $y . '</td>';
}
echo '</tr></table>';
(代表OP发布(。
感谢您的帮助,我明白了。这是答案:
<!DOCTYPE html>
<html>
<head>
<title>Leap Year</title>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.15/datatables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.15/datatables.min.js"></script>
<style>
.table-border{
border:1px solid black;
margin-top: 20px !important;
margin-bottom: 20px !important;
}
header{
text-align: center;
font-size: 50px;
border: 1px solid;
margin-left: 28px;
margin-right: 28px;
margin-top: 20px;
}
</style>
</head>
<body>
<header>Leap Year and Non-Leap year...</header>
<script>
$(document).ready(function() {
$('#table.display').DataTable();
"pagingType": "full_numbers"
} );
</script>
<?php
function isLeap($year) {
return ((($year % 4) == 0) && ((($year % 100) != 0) || (($year % 400) == 0)));
}
for($year=1900; $year<=2100; $year++)
{
If (isLeap($year))
{
$leaps[] = $year;
}
else
{
$nonLeaps[] = $year;
}
}
echo'<div class="col-sm-12">';
echo'<div class="col-sm-6">';
echo'<table style="width: 100%" id="DataTables_Table_0" class=" table-border display dataTable"><tr><th>Leap Year</th></tr>';
foreach($leaps as $y){
echo '<tr>';
echo '<td>' . $y . '</td>';
echo '</tr>';
}
echo '</table></div>';
echo'<div class="col-sm-6">';
echo'<table style="width: 100%" id="DataTables_Table_0" class="table-border display dataTable"><tr><th>Non-Leap Year</th></tr>';
foreach ($nonLeaps as $ny) {
echo '<tr>';
echo '<td>' . $ny . '</td>';
echo '</tr>';
}
echo '</table></div>';
echo '</div>';
?>
</body>
</html>