清除datetimepicker字段中的值 [英] Clear the value in a datetimepicker field

查看:687
本文介绍了清除datetimepicker字段中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确信这很简单,这是我对jquery / javascript的理解让我退缩 - 但我无法让它发挥作用。



全部我需要做的是 - 当 - 单击屏幕上的按钮时,将表单上的某些输入字段清除回其原始值。



这样工作正常,对于除datetimepicker字段之外的所有字段。



以下是代码的相关位,用于定义输入字段:

 < div class ='form-group'id ='START_DATEFormGroup'> 
< label for ='START_DATE'class ='col-sm-2 control-label'data-toggle ='tooltip'data-placement ='top'title =''>开始日期< / label>
< div class ='col-sm-8'>
< div class ='input-group date form_date col-sm-3'data-date-format ='dd M yyyy'data-link-field ='START_DATE'data-link-format ='yyyy- MM-DD'>
< input class ='form-control'size ='16'type ='text'/>
< input type ='hidden'id ='START_DATE'name ='START_DATE'/>
< span class ='input-group-addon'>
< span class ='glyphicon glyphicon-calendar'>
< / span> // group-addon
< / span> // calendar
< / div> // form_date
< / div> // col-sm-8
< / div> // form-group

我正在初始化datetimepicker,如下所示:

  function enableDatepicker(){
$(document).ready(function(){
$('。form_date')。datetimepicker({
格式:'dd M yyyy',
minView:2,
autoclose:1,
})
});
}

要清除输入字段,我有:

  function clearActionForm(){
//此处代码将各种输入字段清除为null或其初始值。
//需要语句将datetimepicker字段清除为null。

}

所以,有人可以给我这一行吗?代码我需要插入clearActionForm()以便将START_DATE字段清空为空。



谢谢。

$('。form_date')。data(DateTimePicker)。clear()



演示


I'm sure this is simple and it's my understanding of jquery/javascript that is holding me back - but I can't get this to work.

All I need to do - is - When a button on the screen is clicked, clear some of the input field on the form back to their original values.

This is working fine, for all fields except a datetimepicker field.

Here is the relevant bits of code, that defines the input field :

<div class='form-group' id='START_DATEFormGroup'>    
<label for='START_DATE' class='col-sm-2 control-label' data-toggle='tooltip' data-placement='top' title=''>Start Date</label>
<div class='col-sm-8'>
<div class='input-group date form_date col-sm-3'  data-date-format='dd M yyyy' data-link-field='START_DATE' data-link-format='yyyy-mm-dd'>
<input class='form-control' size='16' type='text'  />
<input type='hidden' id='START_DATE' name='START_DATE' />
<span class='input-group-addon'>
<span class='glyphicon glyphicon-calendar'>
</span> // group-addon
</span> // calendar
</div> // form_date
</div> // col-sm-8
</div> // form-group

I am initializing datetimepicker as follows :

function enableDatepicker(){
    $( document ).ready(function() { 
         $('.form_date').datetimepicker({
            format: 'dd M yyyy',
            minView: 2,
            autoclose: 1,
            })
    });
} 

To clear the input fields down I have :

function clearActionForm(){
     // code here to clear the various input fields to null or their initial values.
     // Need statements to clear the datetimepicker field to null.

}

So, can someone give me the line(s) of code I need to insert into clearActionForm() in order to clear the START_DATE field to null.

Thanks.

解决方案

use this line $('.form_date').data("DateTimePicker").clear()

Demo

这篇关于清除datetimepicker字段中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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