开发者

changing href attr in jQuery UI datepicker

I'm playing around with the UI datepicker wid开发者_StackOverflow中文版get and I noticed that when the calender is generated, all the dates are inside an anchor tag with href="#". is it possible to change the href to the dateText, or whatever i set the dateFormat to?

ex: <a class="ui-state-default" href="#October-27-2010">27</a>

Thanks in advance

//update

any clues on how to do this?


I suppose you can in this case.

Why would you want to change the href? The datepicker links work with an click-event, so when the link is clicked it won't use the href but it executes the javascript first. And if this script returns false, the href-attribute will never be read (which probably is the case because the URL doesn't get the "#" at the end).

If the script returns true, the link will be executed.

Google will read those links, though, if they lead somewhere (because the indexing-robots ignore javascript as far as I know). Is that what you want to achieve?


I don't see any answer to this and this is a very old question. However, for future reference and incase anyone comes across this problem.

You need to do (in the example below I've used http://localhost:3000/ this is the url my page was on, yours will/could be different. For example: http://www.myamazingsite.com/homepage/):

window.location.href = "http://localhost:3000/" + this.value;

Below is my full code snippet which is working perfectly for me. I read and reference from the Jquery ui Datepicker docs (http://api.jqueryui.com/datepicker/) and also, after research more examples came across this already answered on stackoverflow which extremely similar to what i've done: (Calendar change URL on select with jQuery UI datepicker).

  $("#datepicker")
    .datepicker({
      defaultDate: parsedDate,
      beforeShowDay: $.datepicker.noWeekends,
      dateFormat: "yy/mm/dd",
      onSelect: function(parsedDate) {
        $(this).change();
      }
    })
    .change(function() {
      window.location.href = "http://localhost:3000/" + this.value;
    });

Lastly, the parsedDate is a variable I created above

var parsedDate = $.datepicker.parseDate('yy/mm/dd');

Steps: 1: You need to use an OnSelect event for when you select one of the Jquery UI's dates. 2. You need to do: window.location.href which is used to redirect the page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜