jquerymobile datebox-选择日期后如何调用函数 [英] jquerymobile datebox - How to call a function when date selected

查看:100
本文介绍了jquerymobile datebox-选择日期后如何调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用jquerymobile日期框继承了一些代码。到目前为止,代码集中在使应用程序看起来正确。我需要使其工作,以便在选择日期时,将使用日期和新页面加载来调用服务器。大多数示例只是更改页面中的日期。

I have inherited some code using the jquerymobile datebox. The code so far concentrates on making the application look correct. I need to make it work so that when a date is selected, the server is called with the date and a new page loaded. Most examples just change the date in the page.

到目前为止,代码是:-

The code so far is :-

$('#daycal').live('click', function() {
  $('#catchdate').datebox('open');
});

$( "#catchdate" ).bind( "change", function(event, ui) {
  $("#test1").val("xyz");
});

并且

<div data-role="fieldcontain">
  <label for="catchdate">Some Date</label>
  <input name="catchdate" type="date" data-role="datebox" id="catchdate" data-options='{"mode":"calbox", "useNewStyle":true, "theme":true, "themeHeader":"f", "themeDateHigh":"f", "themeDatePick":"e", "themeDate":"f", "centerHoriz":true}' />
  <input id="test1" type="text"/> <!-- Later changed to a function call -->
</div>

在我的简单测试中,我希望输入的文本在选择日期时发生变化。

In my simple test I expected the text in the input to change when a date was selected.

我看到了一个使用bind to change事件的示例,但我无法使其正常工作。在示例中,我只是更改了input元素中的值,以后将其更改为函数调用。

I have seen an example using the bind to change event, but I cannot get it to work. In the example I was just changing the value in an input element, later this will be changed to a function call.

我还在搜索答案中看到了某个地方,

I also saw somewhere in my search for an answer, a comment that 'live' was deprecated.

最后,我想我可以使用closeCallback( Callbacks( openCallback和 closeCallback)操作起来很简单)。 ..'),但找不到任何应如何使用它的示例。

Finally, I thought I could use closeCallback ('Callbacks ('openCallback' and 'closeCallback') are simple to work with...') but could not find any examples of how it should be used.

要获得所需的功能我需要进行哪些更改?

What changes do I need to make to obtain the functionality I need?

推荐答案

您可以尝试使用日期框的关闭功能,这样,当用户更改他选择的日期并关闭日期框时,您可以调用具有选定日期的服务器方法:

You could try using the close function of the date box, so that when user changes the date selection he makes and closes the date box you can call the server method with the selected date:

$('#DateSelectorId').bind('datebox', function (e, passed) { 
    if ( passed.method === 'close' ) {  
        // selected date
        var date = $('#DateSelectorId').val();          
        // make your service method and change page to another page
    }
});

这篇关于jquerymobile datebox-选择日期后如何调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆