如何与 ajax livesearch 的日期选择器相关联
how is associated to datepicker with ajax livesearch
我有一个问题,如果你能帮忙我会很高兴。我想在搜索框的网站上同时使用 datepicker 和 ajax livesearch。当在搜索框中手动输入日期时,它会添加到搜索框中并结束搜索。如果我 select 来自日期选择器的日期,它会显示在搜索框中,但实时搜索不工作或不搜索。据我了解,livesearch 不处理 datepicker 的结果。我想我需要一个 javascript 来互相获取数据,但我不能。我在等你的帮助。以下代码是相关的。谢谢。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/css/bootstrap-datepicker.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script>
function showResult(str) {
if (str.length==0) {
document.getElementById("livesearch").innerHTML="";
document.getElementById("livesearch").style.border="0px";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (this.readyState==4 && this.status==200) {
document.getElementById("livesearch").innerHTML=this.responseText;
document.getElementById("livesearch").style.border="1px solid #A5ACB2";
}
}
xmlhttp.open("GET","livesearch.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<div class="container">
<div class="row" style="padding-top: 10px">
<div class="col">
<input type="text" size="30" onkeyup="showResult(this.value)" id="datepicker">
</div>
<div id="livesearch"></div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/js/bootstrap-datepicker.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script type="text/javascript">
$('#datepicker').datepicker({
weekStart: 1,
daysOfWeekHighlighted: "6,0",
autoclose: true,
todayHighlight: true,
format: "dd.mm.yyyy",
clearBtn: true,
language: 'tr',
todayBtn: true,
autoclose: false,
dayofweekhiglight: true,
});
$('#datepicker').datepicker("setDate", new Date());
</script>
</body>
</html>
bootstrap 日期选择器有一个 changeDate 事件,您可以使用它来调用 showResult 函数。参见 https://bootstrap-datepicker.readthedocs.io/en/latest/events.html#changedate
我有一个问题,如果你能帮忙我会很高兴。我想在搜索框的网站上同时使用 datepicker 和 ajax livesearch。当在搜索框中手动输入日期时,它会添加到搜索框中并结束搜索。如果我 select 来自日期选择器的日期,它会显示在搜索框中,但实时搜索不工作或不搜索。据我了解,livesearch 不处理 datepicker 的结果。我想我需要一个 javascript 来互相获取数据,但我不能。我在等你的帮助。以下代码是相关的。谢谢。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/css/bootstrap-datepicker.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script>
function showResult(str) {
if (str.length==0) {
document.getElementById("livesearch").innerHTML="";
document.getElementById("livesearch").style.border="0px";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (this.readyState==4 && this.status==200) {
document.getElementById("livesearch").innerHTML=this.responseText;
document.getElementById("livesearch").style.border="1px solid #A5ACB2";
}
}
xmlhttp.open("GET","livesearch.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<div class="container">
<div class="row" style="padding-top: 10px">
<div class="col">
<input type="text" size="30" onkeyup="showResult(this.value)" id="datepicker">
</div>
<div id="livesearch"></div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/js/bootstrap-datepicker.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script type="text/javascript">
$('#datepicker').datepicker({
weekStart: 1,
daysOfWeekHighlighted: "6,0",
autoclose: true,
todayHighlight: true,
format: "dd.mm.yyyy",
clearBtn: true,
language: 'tr',
todayBtn: true,
autoclose: false,
dayofweekhiglight: true,
});
$('#datepicker').datepicker("setDate", new Date());
</script>
</body>
</html>
bootstrap 日期选择器有一个 changeDate 事件,您可以使用它来调用 showResult 函数。参见 https://bootstrap-datepicker.readthedocs.io/en/latest/events.html#changedate