jquery datepicker onselect简单函数
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 onSelect 处理程序语法:
以及文档中的解释:
因此,当您说:
因此作为参数传递 links 实际上并不是您认为的数组,而是在处理程序内部上下文发生了更改。即链接指的是上面提到的所选日期。
Here is the onSelect handler syntax:
And explanation from the docs:
So when you say:
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.