[英]How to get selected date into the text box from the calendar-that popup from Icon?
I am designing a project in Asp.net-MVC 5 with C#. 我正在使用C#在Asp.net-MVC 5中设计一个项目。 I am having a textbox along with a calendar Icon attached at the end. 我在结尾处有一个文本框和一个日历图标。 codings below: 以下代码:
Design: 设计:
<div class="col-md-4 col-lg-4">
<label>From</label>
<div class="input-group date">
<input type="text" name="q" id="txtFrom" class="form-control" >
<span class="input-group-btn">
<button type="submit" name="search" id="datepicker" class="btn btn-flat btn-success">
<i class="fa fa-calendar"></i>
</button>
</span>
</div>
</div>
Script: 脚本:
<script>
$(function () {
$('#txtFrom').datepicker({
autoclose: true
})
})
</script>
This one is working fine, like when I click the text box, the calendar pops up and the selected date was shown in 'From' text box. 这项工作正常,例如当我单击文本框时,日历弹出,并且所选日期显示在“发件人”文本框中。
But, What I need is-the calendar must pop up only if the calendar Icon got clicked and the selected date must be displayed in 'From' Text box. 但是,我需要的是-仅当单击日历图标并且必须在“来自”文本框中显示所选日期时,日历才必须弹出。
If I changed the script as below 如果我如下更改脚本
Script: 脚本:
<script>
$(function () {
$('#datepicker').datepicker({
autoclose: true
})
})
</script>
then the Pop up comes when Calendar Icon got clicked, but the value not sent to the text box. 然后单击“日历”图标,但该值未发送到文本框时,弹出窗口出现。 Image of my TextBox Design : 我的TextBox设计图片:
Kindly Help. 请帮助。 TIA. TIA。
您可以尝试使用html5标签
<input type="date">
If you want to choose year only, like you asked in your comment, see this: 如果您只想选择年份,如您在评论中的要求,请参见:
Can I use an HTML input type "date" to collect only a year? 我可以使用HTML输入类型“日期”来仅收集一年吗?
Or this (even nicer): 或者这个(更好):
`http://jsfiddle.net/lemonkazi/ucfxywh6/`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.