Bootstrap Datepicker - 如何发送值到URL? [英] Bootstrap Datepicker - How to send value to URL?

查看:113
本文介绍了Bootstrap Datepicker - 如何发送值到URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须承认我对Javascript没有希望,PHP更多地在我的舒适区域。



我正在尝试使用Bootstrap Datepicker进行预订系统。我试图找到一种方式,当您点击日期时,它将重新加载页面并将日期发送到URL。



有些东西: http://example.com/test.php?date=2014-02-04



任何帮助将不胜感激!



编辑:简化的代码,拉回日期,但不会发送到URL

 code>< div> 
< form action =test.phpmethod =GET>
< input type =textplaceholder =click to show datepickerid =startDate>
< / form>
< script>
$('#startDate')。datepicker()。on('changeDate',function(){
$(this).parent('form')。submit();
});
< / script>
< / div>




< script type =text / javascript>
//当文档准备好
$(document).ready(function(){

$('#startDate')。datepicker({
格式:dd / mm / yyyy
});

});
< / script>


解决方案

您应该使用方法集获取,然后提交日期更改的表单:

 < form action =test.phpmethod =GET > 
< input id =datename =date>
< / form>

< script>
$('#date')。datepicker()。on('changeDate',function(){
$(this).parent('form')。submit();
});
< / script>


I must admit I'm hopeless on Javascript, PHP is more in my comfort zone.

I'm trying to use Bootstrap Datepicker for a booking system. I'm trying to find a way that when you click on a date it will reload the page and send the date to the URL.

Something like: http://example.com/test.php?date=2014-02-04

Any help would be greatly appreciated!

EDIT: Simplified code, pulls back the date but won't send to URL

<div>
         <form action="test.php" method="GET">
         <input type="text" placeholder="click to show datepicker"  id="startDate">
         </form>
         <script>
         $('#startDate').datepicker().on('changeDate', function() {
         $(this).parent('form').submit();
         });
        </script>
        </div>




   <script type="text/javascript">
        // When the document is ready
        $(document).ready(function () {

            $('#startDate').datepicker({
                format: "dd/mm/yyyy"
            });  

        });
    </script>

解决方案

You should just have it in a form with method set to GET, and then submit the form on date change:

<form action="test.php" method="GET">
    <input id="date" name="date">
</form>

<script>
   $('#date').datepicker().on('changeDate', function() {
         $(this).parent('form').submit();
   });
</script>

这篇关于Bootstrap Datepicker - 如何发送值到URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆