简体   繁体   English

我如何实现$('#calendar')。weekCalendar('今天')?

[英]how do I implement $('#calendar').weekCalendar('today')?

I know very little about javascript so I'm not exactly sure what I'm doing. 我对javascript知之甚少,所以我不确定我在做什么。 Basically, our team is working on a project that uses the jQuery weekcalendar javascript. 基本上,我们的团队正在开发一个使用jQuery weekcalendar javascript的项目。 By default the calendar will display an entire week. 默认情况下,日历将显示整周。

My problem is this: I have multiple css files that fit different screens which I call using another javascript. 我的问题是:我有多个适合不同屏幕的css文件,我使用另一个javascript调用。 For the smallest screen resolution, the one I call for mobiles and the entire calendar wouldn't fit the set width for this resolution so I need to display just the current day. 对于最小的屏幕分辨率,我为移动设备调用的那个和整个日历将不适合此分辨率的设置宽度,因此我需要仅显示当前日期。 I've found on websites that I need to use $('#calendar').weekCalendar("today") but I can't figure out how to implement it and what I should put on the if statement. 我在网站上发现我需要使用$('#calendar').weekCalendar("today")但我无法弄清楚如何实现它以及我应该在if语句中使用什么。

Here's what the code I tried looks like, 这是我试过的代码看起来像,

<script type="text/javascript">
$(document).ready(function () {
    if (document.styleSheets('mobile.min.css')) {
        $('#calendar').weekCalendar('today');
    }
})

Obviously, that doesn't work and I believe its wrong. 显然,这不起作用,我认为它错了。 Can somebody please help me? 有人能帮帮我吗? Thanks. 谢谢。

I haven't used the Adapt js library but looking at it you can implement a callback function. 我没有使用过Adapt js库,但是看一下你可以实现一个回调函数。 That means when the page is resized, it will call your function. 这意味着当页面调整大小时,它将调用您的函数。

so make sure that in your declaration of the ADAPT CONFIG the call back is set. 所以请确保在您的ADAPT CONFIG声明中设置回叫。 In this case 在这种情况下

callback: ChangeCalendar

Then on your page in the script tags, or in the js file you need a callback function to handle the callback. 然后在脚本标签的页面上,或者在js文件中,您需要一个回调函数来处理回调。 it will pass an index corresponding to the size that applies. 它将传递与适用的大小相对应的索引。 I recommend using a switch statement in the callback function to handle the size change. 我建议在回调函数中使用switch语句来处理大小更改。

ChangeCalendar(index, width)
{
switch (index) {
// handles the first item in the range (0 to 760px)
case 0: $('#calendar').weekCalendar('today');
break;
// handles the second item in the range (760 to 980px)
case 1: //something else
break;
// handles everything we missed
default:
break;
}
}

Of course you could vary this to use the width parameter, and then use if statements to handle a set of ranges, such as if (width > 950) { etc } 当然你可以改变它来使用width参数,然后使用if语句来处理一组范围,例如if(width> 950){etc}

I hope this solves your problem. 我希望这能解决你的问题。

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

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