bootstrap-datapicker选择时间后通过传参给所调用的事件

概述,用来bootstrap-datapicker 的日期控件,现在想要获取控件的值,去官网找API,发现居然没有更新文档,只能去stackflow找到了。

直接贴代码吧

<li id="startTime" class="input-append date form_datetime">开始时间: <input  
                            size="20" type="text" value="" readonly> <span  
                            class="add-on calendarIcon"><i  
                                class="icon-calendar glyphicon glyphicon-th"></i></span>  
                        </li>  

获取值:

方法一:

$("#startTime").data("datepicker").getDate()  

方法二:

$("#startTime").find("input").val();  

如果想要有格式化的日期,可以如下操作:

var date = $("#startTime").data("datepicker").getDate(),  

    formatted = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + date.getHours + ":" + date.getMinutes() + ":" + date.getSeconds();  

alert(formatted);  


或者在input标签直接设置 data-format

<input data-format="yyyy-MM-dd hh:mm:ss" type="text"></input>  
发布了25 篇原创文章 · 获赞 10 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/xj932956499/article/details/79817478