这是一个用于选择所有日期的 js 脚本复选框。它适用于 Firefox,但不适用于 Chrome。
<script type="text/javascript" charset="utf-8">
function toggle(source) {
checkboxes = document.getElementsByName('check_time[]');
for each(var checkbox in checkboxes)
checkbox.checked = source.checked;
}
</script>
<?php
session_start();
include ("include/dbconnect.php");
$timestamp = mysql_real_escape_string(strtotime($_POST['date']));
$doc_username = $_SESSION['username'];
$date = @ strip_tags (date("Y-m-d",$timestamp));
$timezone ="Asia/Kuala_Lumpur";
if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);
$todaydate = date("Y-m-d");
if($date == '')
{
echo "<i>Please select a date</i>";
}else if ($date < $todaydate)
{
echo "<i>* You are not allowed to choose date before $todaydate</i>";
}else
{
$inc = 1800;
$start = (strtotime('0830')); // 9 AM
$end = (strtotime('1630')); // 5 PM
echo "<b>*Pick if the time is not available</b><br> <br>";
echo "<form action='doc_confirmtime.php' method='POST'>";
echo "<input type='checkbox' onClick='toggle(this)' />Select All<br/>";
for( $i = $start; $i <= $end; $i += $inc )
{
$timeslot = date( 'G:i:s ', $i + $inc );// to the standart format
$query = mysql_query("SELECT * from appointment Limit 1");
while($row = mysql_fetch_array($query))
{
$date2 = $row['date'];
$time = $row['time'];
$query2 = mysql_query("SELECT doc_username, date, time, status from appointment WHERE (doc_username = '$doc_username' AND date = '$date' AND time = '$timeslot') AND (status = '0' OR status = '1' OR status = '2' OR status is NULL)");
$result = mysql_fetch_array($query2,0);
if ($result > 0)
{
echo "<font size='+1' face='Tahoma, Geneva, sans-serif'><input type='checkbox' name='check_time[]' value='$timeslot' checked = 'checked' DISABLED><b>$timeslot</b></font><br>";
}else
{
echo "<font face='Arial, Helvetica, sans-serif'><input type='checkbox' name='check_time[]' value='$timeslot'>$timeslot</font><br>";
}
}
}
echo "<i>*Highlighted Time has chosen by you or your patient</i>";
echo "<br><br>";
echo "<input type='submit' name='submit' value='Submit' style='width:60px; height=30px' />";
echo "<input type='hidden' name='Date' value='$date' >";
echo "</form>";
}
mysql_close($connect);
?>
这实际上是一个由 JQuery AJAX html 页面运行的 php。输入提交按钮时,会显示日期列表(复选框)和“全选”复选框。Firefox 肯定可以工作,但不能在 Chrome 上工作。