如何使用jquery datepicker获取所选日期的值 [英] How to get value of selected date with jquery datepicker

查看:102
本文介绍了如何使用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选择

这篇关于如何使用jquery datepicker获取所选日期的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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