[英]jQuery set defaul value of date picker input
I am building a web app that uses a date picker to filter the search results of some event items. 我正在构建一个使用日期选择器筛选某些事件项的搜索结果的Web应用程序。
The form submits via ajax just fine, (I am getting results) but I am having issues with setting a default value into the datepicker. 表单通过ajax提交就可以了,(我正在获得结果),但是在将默认值设置为datepicker时遇到了问题。 The input type is text based, but it functions like a javascript DatePicker. 输入类型基于文本,但其功能类似于javascript DatePicker。 Thanks for any help. 谢谢你的帮助。
Note: I did not build the form from scratch, but it is customized to do what I need it to. 注意:我不是从头开始构建表单,而是为完成我需要的内容而定制的。
jQuery: jQuery的:
// Get current date
var date = new Date();
var month = date.getMonth()+1;
var day = date.getDate();
var year = date.getFullYear();
var currentDate = day + "-" + month + "-" + year;
$("#CAT_Custom_2_Min").val(currentDate)
$("#calendar-form").submit();
Form HTML: 表单HTML:
<form id="calendar-form" action="/Default.aspx?CCID=17654&FID=197248&ExcludeBoolFalse=True&PageID=11940414" method="post" name="catcustomcontentform95560">
<table cellspacing="0" cellpadding="2" border="0" class="webform">
<tbody>
<tr>
<td><label>Event Start Time Min/Max:</label><br />
<input type="text" onfocus="displayDatePicker('CAT_Custom_2_Min');return false;" style="background-color: #f0f0f0;" readonly="readonly" class="cat_textbox" id="CAT_Custom_2_Min" name="CAT_Custom_2_Min" />
And <input type="text" onfocus="displayDatePicker('CAT_Custom_2_Max');return false;" style="background-color: #f0f0f0;" readonly="readonly" class="cat_textbox" id="CAT_Custom_2_Max" name="CAT_Custom_2_Max" /></td>
</tr>
<tr>
<td><input type="submit" value="Search" class="cat_button" /></td>
</tr>
</tbody>
</table>
</form>
Live Page: http://sevenclanscasino.designangler.com/warroad/warroad-calendar 实时页面: http : //sevenclanscasino.designangler.com/warroad/warroad-calendar
jsfiddle: http://jsfiddle.net/VJQYb/ jsfiddle: http : //jsfiddle.net/VJQYb/
// Get current date
var date = new Date();
var month = date.getMonth()+1;
var day = date.getDate();
var currentDate = date.getFullYear() + '/' +
(month<10 ? '0' : '') + month + '/' +
(day<10 ? '0' : '') + day;
// Date for 7 days from current date
var futureDate = new Date();
futureDate.setDate(date.getDate() + week);
$("#CAT_Custom_2_Min").val(currentDate);
$("#CAT_Custom_2_Max").val(futureDate);
$("#calendar-form").submit();
I removed the variable d
as it wasn't being declared, and added a #
in front of CAT_Custom_2_Min
and CAT_Custom_2_Max
我删除了未声明的变量d
,并在CAT_Custom_2_Min
和CAT_Custom_2_Max
前面添加了#
you can try 你可以试试
<input type="text" id="date1" />
<script type="text/javascript">
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var cdate = month + "/" + day + "/" + year;
document.getElementById("date1").value=cdate;
</script>
just an example to clear the idea of showing date in input box... 只是一个例子,以清除在输入框中显示日期的想法...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.