javascript - 当我在 Bootstrap 日期范围选择器中更改日期时,更改的日期不会触发
问题描述
在下面的代码中,我想更新在cashadvance查询中使用的from和to变量中输入的选定日期(通过 Bootstrap 日期范围选择器)。我认为它们是日期范围选择器回调函数的问题。
两个变量range_to和range_from的值在 id=reservation 的输入标签中获取,然后在 from 和 to using 中获取它们的值,isset($_GET[range])
但它不起作用。
代码:payrol.php
<?php
include('db.php');
$range_to = date('m/d/Y');
$range_from = date('m/d/Y', strtotime('-30 day', strtotime($range_to)));
?>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>
<body>
<div class="container-fluid">
<div class="box-header with-border">
<div class="pull-left">
<input type="text" class="form-control pull-right col-sm-13" id="reservation" name="date_range" value="<?php echo (isset($_GET['range'])) ? $_GET['range'] : $range_from.' - '.$range_to; ?>">
</div>
</div>
<table>
<thead>
<tr>
<th>Employee ID</th>
<th>Gross</th>
<th>Cash Advance</th>
<th>Range</th>
</tr>
</thead>
<?php
$to = date('Y-m-d');
$from = date('Y-m-d', strtotime('-30 day', strtotime($to)));
if(isset($_GET['range'])){
$range = $_GET['range'];
$ex = explode(' - ', $range);
$from = date('Y-m-d', strtotime($ex[0]));
$to = date('Y-m-d', strtotime($ex[1]));
}
/* **********Fetch Record From Employee ************ */
$sql = "SELECT * from employee";
$query = $con->query($sql);
$total = 0;
while($row = $query->fetch_assoc()){
$empid = $row['id'];
/* ********* Cash Advance Query********* */
$casql = "SELECT *, SUM(aamount) AS cashamount FROM advance WHERE id='$empid' AND adate BETWEEN '$from' AND '$to'";
$caquery = $con->query($casql);
$carow = $caquery->fetch_assoc();
$cashadvance = $carow['cashamount'];
$gross = $row['Salary'] ;
echo "
<tr>
<td>".$row['empid']."</td>
<td>".number_format($gross, 2)."</td>
<td>".number_format($cashadvance, 2)."</td>
<td>".$from."-".$to. "</td>
</tr>
";
}
?>
</table>
</div>
<script>
$(function(){
$("#reservation").on('change', function(){
var range = encodeURI($(this).val());
window.location = 'payrol.php?range='+range;
});
});
</script>
<!--************Date Range Picker********************-->
<script>
$(function() {
//Date range picker
$('#reservation').daterangepicker()
$('input[name="date_range"]').daterangepicker({
opens: 'left'
}, function(start, end, label) {
console.log("A new date selection was made: " + start.format('YYYY-MM-DD') + ' - ' + end.format('YYYY-MM-DD'));
});
});
</script>
</body>
</html>
解决方案
如果对象绑定了事件,请在浏览器中检查。如果没有,您可能需要等待文档准备好才能装订:
$(document).ready(function(){
$("#reservation").on('change', function(){
var range = encodeURI($(this).val());
window.location = 'payrol.php?range='+range;
});
});
推荐阅读
- ios - 从许多不同的 ViewController 呈现 ViewController 的最佳方式
- javascript - 如何在两个数字之间添加一个点?
- asp.net-mvc - 是否可以在没有 Windows 身份验证的情况下获取用户的域?
- c# - c# 使用资源文件缩短数据注释
- jenkins - 在 Jenkins 中,如何接收不同变量名的参数值
- airflow - 气流:无法将“default_timezone”设置为“system”
- c++ - 具有共享指针的观察者
- html - 我们如何在转换为 html 的 xsl 中引用 svg 文件
- c++ - 如何使用`png_image_write_to_file`设置压缩级别?
- php - 使用 pluck 获取唯一值并通过循环存储它们