javascript函数显示当前日期和时间点击清除

时间:2014-05-22 14:43:33

标签: javascript jsp dojo

当我加载JSP页面时,我有日期和TimeTextBox显示当前日期和时间以及其他表单元素,如下拉菜单,文本框,textarea。我编写了一个javascript函数来清除表单元素。问题是当我点击" CLEAR"按钮,日期和TimeTextbox应显示当前日期和时间,目前所有字段都变为空白 我的javascript函数如下:

function clearForm()
 {
     document.getElementById("Country").selectedIndex = 0;
     document.getElementById('State').options.length = 0;
     document.getElementById('PATH').value="";
     $("textarea").val("");
     $("input[type=hidden]").val("");
     return false;
 }

下面是Date和TimeTextbox的jsp代码,它们是使用DOJO创建的。

    SELECT DATE AND TIME : <input name="TIME_SCHEDULE" id="oracle" value="${data.currentDate}" required="true"/>  
     <input id="time" data-dojo-type="dijit/form/TimeTextBox" onChange="require(['dojo/dom'], function(dom){dom.byId('val').value=dom.byId('time1').value.toString().replace(/.*1970\s(\S+).*/,'T$1')})"
        required="true" />
...
<button name="clearButton" id="clearButton" onclick="return clearForm()">CLEAR</button>

默认情况下,当我打开表单时,它显示当前日期和时间,一旦我选择不同的日期和时间并单击清除按钮,我希望日期和TimeTextbox显示最近的日期和时间。

1 个答案:

答案 0 :(得分:0)

当你点击clearButton时,clearForm会被执行。

 onclick="return clearForm()"

在你的clearForm()函数中,你已将它们初始化为空白(“”),如下所示。

$("textarea").val("");
$("input[type=hidden]").val("");

如果你想要最近的日期和时间,你需要调用Date()函数,就像这样。

$("textarea").val(new Date());
相关问题