开发者

Get datepicker value using jQueryUI

开发者 https://www.devze.com 2023-03-19 12:58 出处:网络
Using the jQuery UI, how can I get the value of the date pick开发者_运维百科er in the http post when it\'s used like this within a form:

Using the jQuery UI, how can I get the value of the date pick开发者_运维百科er in the http post when it's used like this within a form:

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


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

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


Are you looking for this.

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


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


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.

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

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


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

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

HTML:

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

JavaScript:

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

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


This worked just fine for me:

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

精彩评论

暂无评论...
验证码 换一张
取 消