如何使用jquery datepicker获取所选日期的值

时间:2012-10-20 06:55:13

标签: jquery jquery-ui datepicker jquery-ui-datepicker

我已经成功使用jQuery datepicker一段时间了。但是,由于我已经开始为我的网站添加更多功能,我需要稍微扩展这个功能。我需要能够获得当前所选日期的值。我的代码如下:

$(document).ready(function() {
        $("#datepicker").datepicker({
            dateFormat: "d MM yy",
            onSelect: function(dateText) 
            { 
                var url = "schedule_backend.php";
                var league = "I need help";
                var data = "date="+ dateText +"&league="+ league;
                $(".schedule_block").load(url, data);
            }
        });

        $("#division_change").change(function() {
            var url = "schedule_backend.php";
            var league = $('input:radio[name=league]:checked', '#league_form').val();
            var date = "I need help";
            var data = 'date='+ date +'&league='+ league;

            $('.schedule_block').load(url, data);
        });
    });

<div class="schedule_block">

</div>

<div id="datepicker">

</div>

<form id="league_form">
    <h1 style="padding:3px;">
        <input type="radio" checked="true" name="league" value="mlb" id="mlb"/> <img src="/img/misc/mlb.png" width="35" height="35" alt="mlb" title="MLB" class="telephone"/> <span style="color:#090127;font-weight:bold;">MLB</span> <br />
    </h1>
    <h1 style="padding:3px;">
        <input type="radio" name="league" value="nfl" id="nfl"/> <img src="/img/nfl/misc/nfl.png" width="35" height="35" alt="nfl" title="NFL" class="telephone"/> <span style="color:#090127;font-weight:bold;">NFL</span> <br />
    </h1>
    <h1 style="padding:3px;">
        <input type="radio" name="league" value="nba" id="nba"/> <img src="/img/nba/misc/nba.png" width="35" height="35" alt="nfl" title="NBA" class="telephone"/> <span style="color:#090127;font-weight:bold;">NBA</span>
    </h1>
    <h1 style="padding:3px;">
        <input type="radio" name="league" value="ncaa" id="ncaa"/> <img src="/img/ncaa/misc/ncaa.png" width="35" height="35" alt="ncaa" title="NCAA" class="telephone"/> <span style="color:#090127;font-weight:bold;">NCAA</span>
    </h1>
</form>

除了datepicker函数的onSelect选项之外,还有其他方法可以获取当前选中的值吗?

1 个答案:

答案 0 :(得分:2)

尝试

$('.selector').datepicker({
   onSelect: function(dateText, inst) { ... }
});

检查此jquery.datePicker example: datePicker into selects