简体   繁体   English

YUI日历:如何禁用nextMonth单击

[英]YUI Calendar: How to disable the nextMonth click

In the YUI Calendar header there are left/right arrows (links) that changes the current month. 在YUI日历标题中,有向左/向右箭头(链接),用于更改当前月份。 I'd like to be able to disable the click event of this links. 我希望能够禁用此链接的click事件。 I tried using changePageEvent() but it happens after the month have changed. 我尝试使用changePageEvent(),但它发生在月份更改后。 YAHOO.util.Event.removeListener didn't seem to work (maybe I'm doing it wrong). YAHOO.util.Event.removeListener似乎不起作用(也许我做错了)。

thanks 谢谢

If changePageEvent() fires too late, why not take the easy way out? 如果changePageEvent()触发得太晚,为什么不采取简单的方法呢? Add the following to your stylesheet and the buttons won't display at all: 将以下内容添加到样式表中,按钮将根本不会显示:

.yui-calendar .calnavleft, .yui-calendar .calnavright{ display:none; }

If that's not what you'd like, you can physically remove the Events by using: 如果这不是您想要的,则可以使用以下方法从物理上删除事件:

YAHOO.util.Event.removeListener(yourCalendarObject.linkLeft,'click');
YAHOO.util.Event.removeListener(yourCalendarObject.linkRight,'click');

But, the buttons will still appear and, since YUI uses a href of "#" on these links, your page will jump to the top. 但是,这些按钮仍然会出现,并且由于YUI在这些链接上使用的href是“#”,因此您的页面将跳到顶部。 You'll need to apply some CSS to hide them either way. 您需要应用一些CSS才能将它们隐藏起来。

You'll have to change the style after the calendar is rendered. 呈现日历后,您必须更改样式。

I did the following and the prev and next buttons were no longer showing: 我做了以下操作,上一个和下一个按钮不再显示:

...

companyCalendar.render();

...

var Dom = YAHOO.util.Dom;
var navLeft = Dom.getElementsByClassName("calnavleft", "a", "companyCalendarContainer")[0];
var navRight = Dom.getElementsByClassName("calnavright", "a", "companyCalendarContainer")[0];

// hide the existing nav buttons
Dom.setAttribute(navLeft, "style", "display: none");
Dom.setAttribute(navRight, "style", "display: none");

You might want to disable "nextMonth click" because you actually want to restrict the input to a certain date at the top. 您可能想要禁用“ nextMonth click”,因为您实际上想将输入限制在顶部的某个日期。 If so, you should be able to set the max date value with calendar API. 如果是这样,您应该可以使用Calendar API设置最大日期值。

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

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