简体   繁体   English

单击日期选择器中的日期时重定向到新页面

[英]Redirecting to new page when clicked on a date in datepicker

I wrote a code for opening the date picker when clicked on the image: 单击图像时,我写了一个打开日期选择器的代码:
Here is the screen shot: 这是屏幕截图:
IMG1
IMG2
And here is the code: 这是代码:
HTML

<div style="position: absolute; top: 127px; left: 31px;">Click
            on image to enter period start date:</div>

        <img src='./img/calendar.png' id="datepickerImage"
            style="position: absolute; top: 160px; left: 126px; height: 75px;" />  

javascript

$(document).ready(function() {
                $("#datepicker").datepicker({
                    changeMonth : true,
                    changeYear : true,
                }).hide().click(function() {
                    $(this).hide();
                });

                $("#datepickerImage").click(function() {
                    $("#datepicker").show();
                });

            });  

The datepicker opens successfully. 日期选择器成功打开。 When any date on the datepicker is clicked, I want it to be redirected to next page. 单击日期选择器上的任何日期时,我希望将其重定向到下一页。 How can I do it? 我该怎么做?

   $('#datepicker').datepicker({
                changeMonth : true,
                changeYear : true,
            }).on('changeDate', function (e) {
       window.open("yourURL", "_self");
   });
   $("#datepickerImage").click(function() {
                $("#datepicker").show();
            });
        });

More info on window.open here http://www.w3schools.com/jsref/met_win_open.asp 有关window.open的更多信息,请点击此处http://www.w3schools.com/jsref/met_win_open.asp

use onSelect method. 使用onSelect方法。

onSelect Type: Function() A callback function when a date is selected. onSelect类型:Function()选择日期时的回调函数。 The function receives the date text and date picker instance as parameters. 该函数接收日期文本和日期选择器实例作为参数。

As @Learner has mentioned in comment with fiddle link. 正如@Learner在小提琴中的评论中提到的那样。

And to redirect use window.location.href with full url. 并重定向使用window.location.href与完整的URL。

window.location.href= 'http://www.google.com'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM