Calendar change URL on select with jQuery UI datepicker

╄→尐↘猪︶ㄣ 提交于 2019-12-12 08:14:30

问题


I am using jQuery UI picker and I am wondering if it's possible when someone pick a date, it automatically redirect them to the URL like so:

index.php?date=2013-10-15

Here's the plug-in I am using.

<script>
    $(function() {
        $( "#datepicker" ).datepicker();
    });
</script>

Date: <input type="text" id="datepicker" />


回答1:


1) What you need is window.location.href, which is the used to redirect the page. You can customize way the window to opened.

2) Once you select the date in datepicker (onSelect), you can combine the change event as @T.J. Crowder said in his answer.

You can try like this

$("#datepicker")
    .datepicker({
      dateFormat: "yy-mm-dd",
      onSelect: function(dateText) {
        $(this).change();
      }
    })
    .change(function() {
      window.location.href = "index.php?date=" + this.value;
    });



回答2:


Try this:

$(function () {
    $("#datepicker").datepicker({
        dateFormat: "yy-mm-dd",
        onSelect: function () {
            window.open(document.URL + '?date=' + this.value);
        }
    });
});

Demo here




回答3:


I hope this will work out as per your requirement.

Date:

<script>
$(function() {
$( "#datepicker" ).datepicker();

});

function myFunc(){
    var dateData = $("#datepicker").val();

    if(dateData != '' ){

        var url = "http://www.index.php?date="+ dateData ;
        window.open(url);

    }
}


</script>

<body>
<p>Date: <input type="text" id="datepicker" onchange="myFunc();" /></p>
</body>


来源:https://stackoverflow.com/questions/19374587/calendar-change-url-on-select-with-jquery-ui-datepicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!