jquery datepicker onselect简单函数

发布于 2024-11-06 17:16:43 字数 1377 浏览 0 评论 0原文

jquery datepicker 插件可以工作,但我想让 onSelect 触发一个在新选项卡中打开页面的函数。

jquery datepicker 插件可以工作,但我想让 onSelect 触发一个在新选项卡中打开页面的函数。

$("#dp").datepicker({
beforeShowDay: highlightDays,

//works perfectly fine

onSelect: function(dates) { window.open('/en/calendar/' + dates, '_self'); },
});

var dates = [new Date(2011, 4 - 1, 28), new Date(2011, 5 - 1, 10),];

//does not work

onSelect: function(links) { window.open('/en/trip/' + links, '_self'); },

var links = [new Link('link1'), new Link('link2'),];

js:

$( "#toggleDP" ).click(function() { $("#dp ").datepicker('show'); });

$("#dp").datepicker({
changeMonth: true,
changeYear: true,
showOn: 'button',
showButtonPanel: true,
buttonImageOnly: true,
buttonImage: "0.gif",
dateFormat: 'yy-mm-dd',
beforeShowDay: highlightDays,
onSelect: function(dates) { window.open('/en/calendar/' + dates, '_self'); },
});


var links =[new Link('test'), new Link('test1'), ];
var dates = [new Date(2011, 4 - 1, 28), new Date(2011, 5 - 1, 10), ];
var txt = ['test','test1',];

function highlightDays(date) {
for (var i = 0; i < dates.length; i++) {
if (dates[i]-date==0) {
return [true, 'markedDay', txt[i],];
}
}
return [false, ''];
}

如果我将 onSelect 设置为 function(links) { window.open('/en/trips/' + links, '_self'); },然后由于某些未知原因,它打开一个带有相应 DATE 的 URL,而不是相应的链接。

The jquery datepicker plugin works, but I'd like to have onSelect triggering a function which opens a page in a new tab.

The jquery datepicker plugin works, but I'd like to have onSelect triggering a function which opens a page in a new tab.

$("#dp").datepicker({
beforeShowDay: highlightDays,

//works perfectly fine

onSelect: function(dates) { window.open('/en/calendar/' + dates, '_self'); },
});

var dates = [new Date(2011, 4 - 1, 28), new Date(2011, 5 - 1, 10),];

//does not work

onSelect: function(links) { window.open('/en/trip/' + links, '_self'); },

var links = [new Link('link1'), new Link('link2'),];

the js:

$( "#toggleDP" ).click(function() { $("#dp ").datepicker('show'); });

$("#dp").datepicker({
changeMonth: true,
changeYear: true,
showOn: 'button',
showButtonPanel: true,
buttonImageOnly: true,
buttonImage: "0.gif",
dateFormat: 'yy-mm-dd',
beforeShowDay: highlightDays,
onSelect: function(dates) { window.open('/en/calendar/' + dates, '_self'); },
});


var links =[new Link('test'), new Link('test1'), ];
var dates = [new Date(2011, 4 - 1, 28), new Date(2011, 5 - 1, 10), ];
var txt = ['test','test1',];

function highlightDays(date) {
for (var i = 0; i < dates.length; i++) {
if (dates[i]-date==0) {
return [true, 'markedDay', txt[i],];
}
}
return [false, ''];
}

if i were to set onSelect to function(links) { window.open('/en/trips/' + links, '_self'); }, then for some unknown reasons, it opens an URL with the corresponding DATE not with the corresponding link.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风为裳 2024-11-13 17:16:43

这是 onSelect 处理程序语法:

function(dateText, inst)

以及文档中的解释:

该函数接收选定的
日期作为文本和日期选择器
实例作为参数。

因此,当您说:

   onSelect: function(links) { window.open('/en/trips/' + links, '_self'); }

因此作为参数传递 links 实际上并不是您认为的数组,而是在处理程序内部上下文发生了更改。即链接指的是上面提到的所选日期。

Here is the onSelect handler syntax:

function(dateText, inst)

And explanation from the docs:

The function receives the selected
date as text and the datepicker
instance as parameters.

So when you say:

   onSelect: function(links) { window.open('/en/trips/' + links, '_self'); }

So passing as a parameter links is not actually the array you think it is but inside the handler the context is changed. i.e. links refers to the selected date as mentioned above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文