jQuery 使用 jQueryUI 获取日期选择器值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6667149/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 21:12:09  来源:igfitidea点击:

Get datepicker value using jQueryUI

jqueryjquery-uidatepicker

提问by ingh.am

Using the jQuery UI, how can I get the value of the date picker in the http post when it's used like this within a form:

使用jQuery UI,当它在表单中像这样使用时,如何在 http 帖子中获取日期选择器的值:

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

回答by jk.

$('#datepicker').datepicker({
    onSelect: function(dateText, inst) {
      $("input[name='something']").val(dateText);
    }
});

Here's a fiddle: http://jsfiddle.net/jensbits/9hbmy/338/

这是一个小提琴:http: //jsfiddle.net/jensbits/9hbmy/338/

回答by naveen

Are you looking for this.

你在找这个吗。

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

回答by ingh.am

Init:

在里面:

$( "#datepicker" ).datepicker({ dateFormat: "yy-m-dd" });

Get value:

获取价值:

$("#datepicker").datepicker().val() //2014-4-15

See format settings at:

请参阅格式设置:

http://api.jqueryui.com/1.9/datepicker/#option-dateFormat

http://api.jqueryui.com/1.9/datepicker/#option-dateFormat

回答by Clayton

You should tie the datepicker to a form input instead of a div, so the value in the input will be submitted back with the form.

您应该将日期选择器绑定到表单输入而不是 div,这样输入中的值将与表单一起提交回来。

<input type="text" id="datepicker"></div>

<script>
    $(function () {
        $('#datepicker').datepicker();
    });
</sript>

回答by Thorsten

Add a hidden field and add it to the "altField" option should do it.

添加一个隐藏字段并将其添加到“ altField”选项应该这样做。

Edit: You might also want to check out this solution:

编辑:您可能还想查看此解决方案:

HTML:

HTML:

<div id="datepicker">KLICK ME</div>
<input type="hidden" id="hidde_date_field" />

JavaScript:

JavaScript:

$('#hidde_date_field').datepicker();

$('#datepicker').click(function() {
    $('#hidde_date_field').datepicker( "show" );
});

回答by spedy

This worked just fine for me:

这对我来说很好用:

$("#datepicker").find(".active").attr("data-date")