手动触发日期选择器 onselect 事件 [英] Fire the datepicker onselect event manually

查看:23
本文介绍了手动触发日期选择器 onselect 事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我你如何触发datepicker的onselect事件?我的代码运行良好(根据 datepickers altfield 的值从数据库中提取一些数据)但是当页面加载时,它不会在当前日期触发 onselect 事件,也不会显示任何内容;所以我想手动完成.

Can anyone tell me how do you trigger the onselect event of datepicker? My code is working well (pulling some data from a database based on the value of datepickers altfield) but when the page loads it doesn't trigger the onselect event on the current date and it doesn't display anything; so I would like to do that manually.

<script>
     $( "#datepicker" ).datepicker
    (
    {
          altField: '#sheet',
          onSelect: function load() {
            $(document).ready(function() {
                    $.ajax({
                    type: 'POST',
                    url: 'test.php',
                    data: {sheetid: $('#sheet').val()},
                    success: function(data)
                    {
                        $("#content").html(data);
                    }
                });

        });
        },
          firstDay: 1});
    </script>

推荐答案

您可以在设置日期后立即在日期选择器上触发 click.

You can trigger a click on the datepicker right after the set of the date.

代码:

$(document).ready(function () {
    $("#datepicker").datepicker({
        altField: '#sheet',
        onSelect: function(date) {
            alert(date);
        },
        firstDay: 1
    });

    $('#datepicker').datepicker("setDate", new Date(2013,09,22) );
    $('.ui-datepicker-current-day').click(); // rapresent the current selected day

});

演示:http://jsfiddle.net/IrvinDominin/DynuW/

这篇关于手动触发日期选择器 onselect 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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