Tag: javascript

如何在特定日期之后阻止Fullcalendar中的日期

我的未来日期总是比当前日期提前30天。 它存储在Date对象中。 我用它来解决这个问题: var currentDate = new Date(); var futureBlockDate = new Date(); futureBlockDate.setDate(currentDate.getDate() + 30); 使用FullCalendar jQuery插件,我希望在日历上以不同的背景颜色直观地阻止此日期之后的任何日期,以便用户知道他们无法点击它们或在那些日子创建活动。 使用FullCalendar执行此操作的最佳方法是什么? 也许默认情况下禁用所有日期,并且仅启用特定范围(从今天的日期到将来的30天)? 我想我可以使用以下代码将禁用的背景状态应用于所有单元格: $(“.fc-widget-content”).addClass(“disabled”); .disabled .fc-day-content { background-color: #123959; color: #FFFFFF; cursor: default; } 怎么做到呢?

服务器发送事件轮询导致长时间延迟

我有一个连接器,它将使用cURL和PHP调用RESP API。 我需要每秒调用一个方法来检查新消息然后处理它们。 我使用以下两种方法来处理消息 使用SetInterval() AJAX轮询:每秒调用一次php脚本。 除非我无法防止多个SetInterval()从浏览器的不同选项卡同时运行,否则这种方法很有效。 (我不想让用户打开10个浏览器选项卡,这导致一个用户有10个SetInterval()同时运行。 使用EventSource服务器发送事件:一旦队列中有新数据,服务器将发送更新浏览器。 这会减慢响应时间。 我对脚本的每次调用都需要大约20秒才能完成,这是一个问题。 我不确定为什么会这样。 这是我的SetInterval()实现 function startCalls(){ //update the screen using Intervals refreshIntervalId = setInterval(function() { $.getJSON(“index.php”, {‘method’: ‘getMessages’, ‘jSON’: true} , function(data){ processServerData(data); }); }, 1000); } 一旦用户登录我就调用了这个函数startCalls() 在index.php文件中我有这个代码要调用 if($method == ‘getMessages’){ $messaging = new ICWS\Messaging($icws); $messaging->processMessages(); $myQueue = $messaging->getCallsQueue(); echo json_encode($myQueue ); } 这是我的第二个实现“Server-Sent Events” […]

在预检响应中,Access-Control-Allow-Headers不允许使用请求标题字段Access-Control-Allow-Headers

我试图从跨域创建一个登录页面,但我无法解决问题,错误是: XMLHttpRequest无法加载http://localhost/testing/resp.php 。 在预检响应中,Access-Control-Allow-Headers不允许使用请求标题字段Access-Control-Allow-Headers。 我的Javascript代码是: $(‘#login’).click(function(){ var username = $(‘#uname’).val(); var password = $(‘#pass’).val(); var result = $(‘.result’); result.text(‘loading….’); if (username != ” && password !=”){ var urltopass = ‘action=login&username=’+username+’&password=’+password; $.ajax({ type: ‘POST’, data: urltopass, headers: {“Access-Control-Allow-Headers”: “Content-Type”}, url: ‘http://localhost/testing/resp.php’, crossDomain: true, cache: false, success: function(responseText){ console.log(responseText); if(responseText== “0”){ result.text(‘incorrect login information’); } else if […]

使用php和jquery ajax从mysql数据库中获取数据

我想使用php和jquery ajax从mysql数据库中获取数据。 ‘process.php’是连接数据库并获取mysql数据的php文件。 它在单独运行时有效,但是当使用ajax调用时它不起作用。 有人可以帮助纠正错误吗? 这是我的html文件: $(document).ready(function(){ function showRoom(){ $.ajax({ type:”POST”, url:”process.php”, data:{action:showroom}, success:function(data){ $(“#content”).html(data); } }); } showRoom(); }); 这是我的process.php文件 <?php $link=mysqli_connect("localhost","root","raspberry","homebot"); if (mysqli_connect_errno()) echo "Failed to connect to MySQL: " . mysqli_connect_error(); $action=$_POST["action"]; if($action=="showroom"){ $query="SELECT * FROM user"; $show=mysqli_query($link,$query) or die ("Error"); while($row=mysqli_fetch_array($show)){ echo "$row[‘name’]”; } } ?>

jQuery cookies设置页面刷新后选择下拉值

老实说,今天到目前为止,我的大脑相当油炸。 我正在尝试使用此插件保存页面上多个选择下拉列表的状态: http://plugins.jquery.com/project/cookies 我正在使用这个jQuery根据他们的ID设置不同标题下拉列表的cookie: $(document).ready(function() { // hide ‘Other’ inputs to start $(‘.jOther’).hide(); // event listener on all select drop downs with class of jTitle $(“.jTitle”).change(function(){ //set the select value var val = $(this).val(); if(val != “Other”) { //$(this).nextAll(‘.jOther’).hide(); $(this).parent().find(“.jOther”).hide(); } else { //$(this).nextAll(‘.jOther’).show(); $(this).parent().find(“.jOther”).show(); } // Sets a cookie with named after the title […]

将多个键绑定到按键事件

我目前正在使用此Javascript kepypress代码在按键时触发事件: $(document).keydown(function(e) { switch(e.keyCode) { case 39: e.preventDefault(); alert(“Arrow Key”); break; case 37: e.preventDefault(); alert(“Arrow Key”); } }); 但我想知道的是,如果我可以而不是绑定一个键绑定两个键的组合。 我可以这样做: $(document).keydown(function(e) { switch(e.keyCode) { case 39 && 37: e.preventDefault(); alert(“Arrow Key”); break; } });

触摸设备,单击和双击事件处理程序jQuery / Javascript?

背景: 我的网站是magento开源电子商务解决方案,在顶部(标题)它有一个购物车图标。 在dekstop上,当用户将鼠标hover在该图标上时,它会显示购物车中的内容(项目)。 但是点击该图标,用户可以访问购物车页面。 我想要: 我希望只有触摸设备才有能力,当用户单击图标时,它应该只显示内容,但是当双击图标时,它应该将它们带到购物车页面。 HTML代码:   My Bag (1) $28   我已经尝试过的: jQuery(function($){ /* Code to detect the user agent, if mobile device then execute the code*/ if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) { // on single touch $(“#mini-cart .dropdown-toggle”).on(‘click’, ‘a’, function(e){ e.preventDefault(); $(“#mini-cart .dropdown-menu”).show(); }); // on double touch $(“#mini-cart .feature-icon-hover”).find(‘a’).dblclick(function(e){ location.href = ‘/checkout/cart’; //alert(‘dblclick’); […]

如何像Facebook一样创建标题提醒效果?

如何像facebook一样创建闪烁的标题效果? 意味着,当您与某人聊天并收到新消息时,标题开始在原始标题和消息之间切换,通知用户新消息的到达会产生闪烁效果。 AdrianoKF的解释: 注意窗口标题在收到新聊天消息之后在“Foo Bar的新消息”和常规消息之间循环。

用于处理私有函数的jQuery插件设计模式(通用实践?)

我一直在开发jQuery插件很长一段时间了,我想我现在知道如何设计一个好的插件。 然而,有一个问题一直困扰着我,那就是如何以强大而优雅的方式处理私有function。 我的插件通常看起来像这样: (function($) { $.fn.myplugin = function(…) { … // some shared functionality, for example: this.css(‘background-color’, ‘green’); … }; $.fn.mypluginAnotherPublicMethod = function(…) { … // some shared functionality, for example: this.css(‘background-color’, ‘red’); … }; }(jQuery)); 现在我的问题是:如何巧妙地干掉共享function? 一个明显的解决方案是将它放在插件命名空间中的函数中: var fill = function($obj, color) { $obj.css(‘background-color’, color); }; 虽然这个解决方案很有效且命名很好,但我真的不喜欢它。 原因很简单:我必须传递jQuery对象。 即我必须这样称呼它: fill(this, ‘red’); 虽然我想这样称呼: this.fill(‘red’); 当然,我们可以通过简单地将fill放入jQuery.fn来实现这个结果。 […]

jQuery’每个’循环使用JSON数组

我正在尝试使用jQuery的each循环来遍历此JSON并将其添加到名为#contentHere的div 。 JSON如下: { “justIn”: [ { “textId”: “123”, “text”: “Hello”, “textType”: “Greeting” }, { “textId”: “514”, “text”:”What’s up?”, “textType”: “Question” }, { “textId”: “122”, “text”:”Come over here”, “textType”: “Order” } ], “recent”: [ { “textId”: “1255”, “text”: “Hello”, “textType”: “Greeting” }, { “textId”: “6564”, “text”:”What’s up?”, “textType”: “Question” }, { “textId”: “0192”, “text”:”Come over […]