本文介绍了jQuery Mobile Datebox截取日期选择点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 http://dev.jtsage上的jquery移动日期框. com/jQM-DateBox2/demos/fullopt.html 特别是我在 http://dev.jtsage.com/cdn/datebox/1.1.0/jqm-datebox-1.1.0.mode.calbox.js

I am using the jquery mobile datebox at http://dev.jtsage.com/jQM-DateBox2/demos/fullopt.htmlIn particular I am using the calbox option at http://dev.jtsage.com/cdn/datebox/1.1.0/jqm-datebox-1.1.0.mode.calbox.js

我需要拦截当您单击某天然后执行自定义操作(例如更改该日期的背景颜色)时触发的click事件.最好的方法是什么?我试图为元素$('div.ui-datebox-griddate.ui-corner-all.ui-btn-up-d')注册一个click事件,但这似乎不起作用.

I need to intercept the click event that is triggered when you click on a day and then do something custom (E.g. change the background color of that date). What is the best way of doing this? I tried to register a click event for the element $('div.ui-datebox-griddate.ui-corner-all.ui-btn-up-d') but that does not seem to be working.

我正在使用bonesjs,coffeescript中类的相关部分看起来像(SimpleView扩展了Backbone.View):

I am using backbonejs and the relevant portion of the class in coffeescript looks something like (SimpleView extends Backbone.View):

class A extend SimpleView
  ....
  events: {
    'click div.ui-datebox-griddate.ui-corner-all.ui-btn-up-d': "clicked"
  }

  clicked: (event) ->
    console.log 'clicked'

上面的方法不起作用,而且这也许不是执行我想要的最佳方法,因为它依赖于内部类的名称来创建click事件.

The above does not work and moreover this perhaps is not the best way to do what I want since it depends on internal class names to create the click event.

提前谢谢!

推荐答案

Datebox触发一个名为"datebox"的自定义事件(足够多了).单击一天时会触发该事件3次,但更重要的是,它会将事件的第二个参数传递给事件,该参数包含有关单击当天的详细信息.

Datebox triggers a custom event called "datebox" (creatively enough). The event is fired three times when a day is clicked, but more importantly, it passes a second argument to the event that has the details about the day being clicked.

试一下:

....
events: {
    'datebox' : 'clicked'
},

clicked: function(e, eventDetail) {
    // Of the three event triggers, "method" varies, so I checked for "set"
    if (eventDetail.method == "set") {
        var jsDateObj = eventDetail.date;
        console.log(jsDateObj);
    }
}
....

这篇关于jQuery Mobile Datebox截取日期选择点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 20:04