How to get value of selected date with jquery datepicker

自古美人都是妖i 提交于 2019-12-02 15:16:31

问题


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>

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


回答1:


try like

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

check this jquery.datePicker example: datePicker into selects



来源:https://stackoverflow.com/questions/12986071/how-to-get-value-of-selected-date-with-jquery-datepicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!