如何从jquery datepicker获取所选日期 [英] How to get the selected date from jquery datepicker

查看:99
本文介绍了如何从jquery datepicker获取所选日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jquery datepicker来显示一个日历。根据我的要求,我想要获取用户在我的应用程序中使用的jQuery变量中选择的日期,但是我无法获取日期。
这是datepciker的代码

I am using jquery datepicker to show a calendar.Now as per my requirement i want to get the date selected by the user in my jquery variable which i will use in my application but i am not able to get the date .. Here is the code for datepciker

<div id="datepicker"></div>

这里我正在尝试获取所选的代码..

and here i am trying to get the selected code..

$(document).ready(function () {

        $("#datepicker").datepicker({
            onSelect: function (dateText, inst) {
                var date = $(this).val();
                alert(date);
            }
        });

    });

但是,我无法获得日期..请帮助我..谢谢..

But, I am not able to get the date ..Please help me ..Thanks..

推荐答案

这应该是窍门

$(function() {
    $("#datepicker").datepicker();
    $("#datepicker").on("change",function(){
        var selected = $(this).val();
        alert(selected);
    });
});

它的基本,但这里是一个 jsfiddle ,它在选择时提醒所选日期

Its basic but here is a jsfiddle with it alerting the selected date when selected

更新更改日期格式

$(function() {
    $( "#datepicker" ).datepicker({ dateFormat: "yy-mm-dd" });
    $("#datepicker").on("change",function(){
        var selected = $(this).val();
        alert(selected);
    });
});

jsfiddle

第3次更新

$(function() {
    $("#datepicker").datepicker({ 
        dateFormat: "yy-mm-dd", 
        onSelect: function(){
        var selected = $(this).val();
        alert(selected);
        }
    });
});

我已经使用了一些更多的原生标记为 datepicker ui这里尝试这个,看看你是否像以前那样获得警报。

I have used a little more of the native markup for datepicker ui here try this and see if you get the alert as you are after.

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

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