JQuery的日期选择器获取选择日期 [英] JQuery Datepicker Get Selected Date

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

问题描述

我目前正在与我已经修改的格式,以便能够通过存储在后端的MySQL数据库2个独立的JQuery datepickers。

I am currently working with 2 separate JQuery datepickers that I have modified the format to be able to pass through to store in a backend MySQL db.

<script>
$(function() {
$( ".datepicker" ).datepicker({
        inline: true,
        showOtherMonths: true,
        dateFormat: 'yy-mm-dd',
        dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],  
    });
});
</script>


我的日期选择在这里名为


My date pickers are called here

<input type="text" class='datepicker' name="datepicker1" />
<input type="text" class='datepicker' name="datepicker2" />

我一直在试图让选定的日期通过通过AJAX到PHP。我已经使用了GETDATE函数尝试,但还没有多少运气。

I have been trying to get the selected date to pass to php via ajax. I have tried using the getDate function but have not had much luck.

$(日期选择器。)日期选择器('GETDATE');

$(".datepicker").datepicker( 'getDate' );

推荐答案

既然你有两个元素与类 .datepicker ,选择不会知道可以选择哪个元素。所以,你必须指定你想获得之日起输入的名称。

Since you have two elements with the class .datepicker, the selector wont know which element to choose from. So, you'll have to specify the name of the input you're trying to get the date from.

first = $(".datepicker[name=datepicker1]").datepicker('getDate');
second = $(".datepicker[name=datepicker2]").datepicker('getDate');

演示: http://jsfiddle.net/hungerpain/TWmcD/

注意:

不会 VAL()比使用容易 GETDATE ?你可以格式化你的code日期在MySQL本身并保存你的工作,在客户方。

Won't val() be easier than using getDate? You could format your code date in mysql itself and save work for you in the clientside.

first = $(".datepicker[name=datepicker1]").val();
second = $(".datepicker[name=datepicker2]").val();

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

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