当我打开页面并单击日历显示按钮时,我会获得当前日期的数据库条目。我想要在不按任何按钮的情况下实现这一点。我如何解决它?
<script language="JavaScript" type="text/javascript" src="calendar/calendar.js"></script>
<script src="jquery.js"></script>
<script>
$(document).ready(function()
{
//ajaxTime.php is called every second to get time from server
var refreshId = setInterval(function()
{
$('#timeval').load('ajaxTime.php?randval='+ Math.random());
}, 1000);
//stop the clock when this button is clicked
$("#stop").click(function()
{
clearInterval(refreshId);
});
});
</script>
<!--<strong><div align="right" id="timeval" style="color:#FF6600; font-family:Arial, Helvetica, sans-serif">--:--:--</div></strong>-->
<table width="420" border="1" >
<form name="showdraw" action="ooo.php" method="get">
<tr bgcolor="#FF6600">
<td><script> DateInput('cdate', true, 'YYYY/MM/DD'); </script></td>
<td> <input type="submit" value ="Show">
</tr>
<tr bgcolor="#FF6600">
<td><center><font color=#2F4F4F><h2>Draw Time</h2></font></center></td>
<td><center><font color=#2F4F4F><h2>Wining Number</h2></font></center></td>
</tr>
</form>
<tbody>
<?php
include('connect.php');
if (isset($_GET["cdate"])) { $cdate = $_GET["cdate"]; } else { $cdate = ('Y-m-d h:m:s'); };
$result = $db->prepare("SELECT * FROM birthday WHERE date = :a");
$result->bindParam(':a', $cdate);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
?>
<tr class="record">
<tr bgcolor="#EEF3E2">
<td><font size=5><font color='#008B00'><?php echo $row['dt']; ?></font></td>
<td><font size=5><font color='#008B00'><?php echo $row['wn']; ?></font></td>
<?php
}
?>
答案 0 :(得分:1)
使用jQuery的 trigger() 来模拟所需元素的click
事件。
在$(document).ready(function(){
$('input[value="Show"]').trigger( "click" );
这将模拟显示按钮上的单击,并应触发单击显示按钮时通常会发生的情况。