使用Bootstrap Datepicker时如何获取选定的日期值? [英] How to get the selected date value while using Bootstrap Datepicker?
问题描述
使用jquery和引导DatePicker,如何获取使用Bootstrap Datepicker选择的新日期值?
FYI,我正在使用Rails 3和Coffescript。
Using jquery and the Bootstrap Datepicker, how do I get the new date value I selected using the Bootstrap Datepicker? FYI, I'm using Rails 3 and Coffescript.
我使用以下设置数据触发器:
I set up the datapicker using:
<input id="startdate" class="span2 datepicker" type="text" value="" name="startdate" default="2013-05-21" data-date="2013-05-21" data-behavior="datepicker">
<%= submit_tag 'Get Data using date', :id => 'get_data' %>
$(".datepicker").datepicker
endDate: new Date
format: "yyyy-mm-dd"
autoclose: true
minViewMode: 1
todayBtn: "linked"
当用户点击获取数据使用日期按钮,我将使用jQuery获取由datepicker设置的新日期值,阻止表单使用该日期值提交并运行ajax请求。所有的ajax运行良好,除了得到正确的新日期值。我尝试了以下两个,它不给我新的日期,它只返回我初始设置的默认值。
When a user clicks on the "get data using date" button next to it, I will use jQuery to get the new date value set by the datepicker, prevent the form from submitting and run an ajax request using that date value. All the ajax is running well, except for getting the correct new date value. I tried both of the following and it doesn't give me the new date, it only return the defaults I initially set.
sd1 = $('#startdate').attr('value')
console.log sd1
sd2 = $('#startdate').attr('data-date'))
console.log sd2
我现在感觉真的很愚蠢,但我可以'找出如何获取引导程序datepicker设置的新日期值。
I am feeling really stupid right now, but I can't find out how to get the new date value set by the bootstrap datepicker.
推荐答案
你可以尝试这个
$('#startdate').val()
或
$('#startdate').data('date')
这篇关于使用Bootstrap Datepicker时如何获取选定的日期值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!