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

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

问题描述:

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

I've been using the jQuery datepicker quite successfully for some time now. But, since I've began to add more features to my site, I need to expand on this function a bit. I need to be able to get the value of the date that is currently selected. My code is as follows:

$(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>

有没有其他方法可以获取当前选择的值,而不是onSelect选项datepicker函数?

Is there any other way for me to get the value that is currently selected other than the onSelect option for the datepicker function?

尝试像

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

检查这个 jquery.datePicker示例:datePicker选择