使用 Bootstrap Datepicker 时如何获取选定的日期值? [英] How to get the selected date value while using Bootstrap Datepicker?

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

问题描述

使用 jquery 和 Bootstrap Datepicker,如何获取我使用 Bootstrap Datepicker 选择的新日期值?仅供参考,我使用的是 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 获取日期选择器设置的新日期值,防止表单提交并使用该日期值运行 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

我现在感觉很愚蠢,但我不知道如何获取引导程序日期选择器设置的新日期值.

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屋!

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