为什么第一次点击时没有调用函数? [jQuery的]

时间:2015-12-02 00:03:23

标签: jquery click

为什么首次单击元素时不会调用<?php session_start(); include('../include/page_header2.php'); $id = $_GET['id']; $maid_q = mysql_query("SELECT * FROM maid WHERE id = '".$id."'"); $get_maid = mysql_fetch_assoc($maid_q); $maid = $get_maid['full_name']; ?> <style> .submit_style { color : #eee; padding:4px; border : none; // Where are you getting this "IMAGE_PATH" vvv background:transparent url("<?php echo IMAGE_PATH.'remove.png'; ?>") no-repeat; cursor: pointer; background-size:21px 21px; text-indent: -1000em; width:25px; } </style> <script> function goLastMonth(month, year, id){ if(month == 1) { --year; month = 13; } --month // Missing ; var monthstring= ""+month+""; var monthlength = monthstring.length; if(monthlength <=1){ monthstring = "0" + monthstring; } document.location.href ="<?php $_SERVER['PHP_SELF'];?>?month="+monthstring+"&year="+year+"&id="+id; } function goNextMonth(month, year, id){ if(month == 12) { ++year; month = 0; } ++month // Missing ; var monthstring= ""+month+""; var monthlength = monthstring.length; if(monthlength <=1){ monthstring = "0" + monthstring; } // You need to echo this "$_SERVER['PHP_SELF']" document.location.href ="<?php $_SERVER['PHP_SELF'];?>?month="+monthstring+"&year="+year+"&id="+id; } </script> <style> .today{ background-color: #CCCCCC; } .event{ background-color: #AFE2FE; } #session_list{ font-size:8px; } #name_list{ font-size:7px; } a{text-decoration:none; color: #000000} a:active{ text-decoration:none; color: #000000} a:hover{ text-decoration:none; color: #000000} </style> <?php if (isset($_GET['day'])){ $day = $_GET['day']; } else { $day = date("j"); } if(isset($_GET['month'])){ $month = $_GET['month']; } else { $month = date("n"); } if(isset($_GET['year'])){ $year = $_GET['year']; }else{ $year = date("Y"); } $currentTimeStamp = strtotime( "$day-$month-$year"); $monthName = date("F", $currentTimeStamp); $numDays = date("t", $currentTimeStamp); $counter = 0; ?> <title>L.T.K. Cleaning System</title><div align="center"> <table width="80%" bgcolor="#EEEEEE" > <tr> <td width="14.3%"><div align="right"><input type='button' value=' < 'name='previousbutton' class="all_btn" onclick ="goLastMonth(<?php echo $month.",".$year.",".$id ?>)"></div></td> // Missing ; <td colspan="5"><div align="center"><?php echo $monthName.", ".$year; ?></div></td> <td width="14.3%"><input type='button' value=' > 'name='nextbutton' class="all_btn" onclick ="goNextMonth(<?php echo $month.",".$year.",".$id?>)" /></td> // Missing ; </tr> </table> <table width="80%" class="tableFormat2" id="main_tbl2" bgcolor="#EEEEEE" frame="box"> <tr> <th width="14.3%">Sun</th> <th width="14.3%">Mon</th> <th width="14.3%">Tue</th> <th width="14.3%">Wed</th> <th width="14.3%">Thu</th> <th width="14.3%">Fri</th> <th width="14.3%">Sat</th> </tr> <?php echo "<tr>"; for($i = 1; $i < $numDays+1; $i++, $counter++) { $timeStamp = strtotime("$year-$month-$i"); if($i == 1) { $firstDay = date("w", $timeStamp); for($j = 0; $j < $firstDay; $j++, $counter++) { echo "<td>&nbsp;</td>"; } } if($counter % 7 == 0) { echo"</tr><tr>"; } $monthstring = $month; $monthlength = strlen($monthstring); $daystring = $i; $daylength = strlen($daystring); if($monthlength <= 1) { $monthstring = "0".$monthstring; } if($daylength <=1) { $daystring = "0".$daystring; } $todaysDate = date("Y-m-d"); $dateToCompare = $year. '-' . $monthstring. '-' . $daystring; echo "<td valign='top' align='right' "; if ($todaysDate == $dateToCompare) { echo "class ='today'"; } else { $sqlCount = "select * from service where recurring_date LIKE '%".$dateToCompare."%' and available_maid like '%$maid%'"; $get_sql = mysql_query($sqlCount); $noOfEvent = mysql_num_rows(mysql_query($sqlCount)); if($noOfEvent >= 1) { echo "class='event'"; } } echo ">"; echo "<a href='".$_SERVER['PHP_SELF']."?year=".$year."&month=".$monthstring."&day=".$daystring."&id=".$id."&v=true'>".$i."<br />"; while($session_q = mysql_fetch_array($get_sql)){ $count1++; // Can't find this declared? $customer_id= $session_q['customer_id']; $sqlcust1 = mysql_query("SELECT * FROM customer where id = '$customer_id' "); $get_custinfo1 = mysql_fetch_assoc($sqlcust1); echo "<table name='schedulelist' id='schedulelist' class='schedulelist'><tr valign ='top'><td><div id='name_list'>";?> // Where are you getting vvv <img src=<?php echo IMAGE_PATH.'dot.png'; ?> width="5"/> <?php echo $get_custinfo1['customer_name']."</div></td>"; echo "<td>"; $maid_name=explode(",",$session_q['available_maid']); $countmaid=count($maid_name); for($maidi=0;$maidi<$countmaid;$maidi++) { echo "<div id='name_list'>";?> <img src=<?php echo IMAGE_PATH.'dot.png'; ?> width="5"/> <?php echo $maid_name[$maidi]; echo "</div>"; } echo "<td>"; echo "<div id='name_list'>"; echo $session_q['service_session']."</div>"; echo "</td></tr></table>"; }?><input type="hidden" name="ctr" id="ctr" value="<?php echo $count1; ?>"> // Again, can't find $count1 declared <?php echo "</a></td>"; } echo "</tr>"; ?> </table> <?php if(isset($_GET['v'])) { $_SESSION['id'] = $id; $_SESSION['day'] =$day; $_SESSION['month'] =$month; $_SESSION['year'] =$year; $maid_q = mysql_query("SELECT * FROM maid WHERE id = '".$id."'"); $get_maid = mysql_fetch_assoc($maid_q); $maid = $get_maid['full_name']; $sqlEvent = "select * FROM service where recurring_date LIKE '%".$year."-".$month."-".$day."%' and available_maid like '%$maid%'"; $resultEvents = mysql_query($sqlEvent); echo "<br />Occupancy for <strong>".$day." ".$monthName." ".$year."</strong><br />"; ?> <table class='tableFormat' id='main_tbl' width='80%'> <tr> <th>No</th> <?php if($_SESSION['login_level'] == 'Admin') { ?> <th><input type="checkbox" name="select_all" id="select_all"></th> <th>Service Session</th> <?php } ?> <th>Customer Name</th> <th style="color:#609;"><label id="selected_item"></label></th> </tr> <?php $counter = ''; while ($events = mysql_fetch_array($resultEvents)) { $counter++; ?> <tr align="center"> <td><?php echo $counter; ?></td> <?php if($_SESSION['login_level'] == 'Admin') { ?> <td><input type="checkbox" name="id_<?php echo $counter; ?>" id="id_<?php echo $counter; ?>" value="<?php echo $events['id']; ?>" onclick="check(this.value)"></td> <?php } ?> <td><?php echo $events['service_session']; ?></td> <td><?php $customer_id= $events['customer_id']; $sqlcust = mysql_query("SELECT * FROM customer where id = '$customer_id' "); $get_custinfo = mysql_fetch_assoc($sqlcust); echo $get_custinfo['customer_name']; ?> </td> <td> <a href="view_service.php?id=<?php echo $events['id']; ?>" target="_self"><img src=<?php echo IMAGE_PATH.'view.png'; ?> width="17" title="View Details" id="view"></a>&nbsp;&nbsp; </td> </tr> <?php } ?> <input type="hidden" name="ctr" id="ctr" value="<?php echo $counter; ?>"> </table> <?php } ?> <br /> <input type="button" name="close" id="close" value="Close" class="all_btn" onClick="window.parent.location.href='maid.php'"> </div> <script> $(document).ready(function() { $('#bc').html("<a href='booking.php'>Scheduled Service</a>"); $("#customer").autocomplete("auto_custName.php", { width: 270, matchContains: true, selectFirst: false }); }); $(function() { $('.nm3').nyroModal({}); }); $("#select_all").click(function() { $counter = $("#ctr").val(); // This is not PHP here. Why the '$' ?? if($('#select_all').is(':checked')) { for($i = 1; $i <= $counter; $i++) // This is not PHP here. Why the '$' ?? { $("#id_" + $i).attr('checked', true); } $("#selected_item").html($counter + " selected" + '&nbsp;&nbsp;<input type="submit" name="sub-del" id="sub-del" class="submit_style" value="sub-del" title="Delete All" style="color:#eee;">'); }else { for($i = 1; $i <= $counter; $i++) // This is not PHP here. Why the '$' ?? { $("#id_" + $i).attr('checked', false); // This is not PHP here. Why the '$' ?? } $('#selected_item').text(''); } }); function check(id) { $counter = $("#ctr").val(); // This is not PHP here. Why the '$' ?? $ctr = 0; // This is not PHP here. Why the '$' ?? for($i = 1; $i <= $counter; $i++) // This is not PHP here. Why the '$' ?? { if($('#id_'+$i).is(':checked')) // This is not PHP here. Why the '$' ?? { $ctr++; // This is not PHP here. Why the '$' ?? } } if($ctr > 0) // This is not PHP here. Why the '$' ?? { $("#selected_item").html($ctr + " selected" + '&nbsp;&nbsp;<input type="submit" name="sub-del" id="sub-del" class="submit_style" value="sub-del" title="Delete All" style="color:#eee;">'); }else { $("#selected_item").text(""); } } function deleteConfirmation(name, id){ $id = id; $.confirm({ 'title' : 'Delete Confirmation', 'message' : 'Are you sure want to delete ' + name + ' scheduled service record?', 'buttons' : { 'Yes' : { 'class' : 'blue', 'action': function(){ $.ajax({ type: 'POST', data: { action: 'delete_service', id: $id, }, url: 'action.php', success: function(){ location.reload(); } }) } }, 'No' : { 'class' : 'gray', 'action': function(){} // Nothing to do in this case. You can as well omit the action property. } } }); } </script> </body> </html> 函数,仅在第二次等?

toggleSidebar()

1 个答案:

答案 0 :(得分:0)

因为您已经嵌套了定义,所以尝试将内部$()。mousedown ...等调用移出.click()函数。