简体   繁体   English

如何从日历的文本框中(从Icon弹出窗口)获取选定的日期?

[英]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设计图片:

我的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.

相关问题 从日历中选择日期到文本框 - selected date from calendar into text box 如何将日历中的选定月份显示到 WPF 的文本框中? - How to display selected month from Calendar into text box in WPF? 使用C#中的按钮从月份日历中获取文本框中的日期 - Get Date in Text Box from month calendar with button in c# C#从日历中获取选定的日期并将其显示在消息框中 - C# getting a selected date from calendar and displaying it in a message box 从富文本框中获取所选文本 - get the selected text from the rich text box 使用月历来获取所选周的星期六日期值 - Get saturday date value from a selected week using a month calendar DateTimePicker:如果用户在弹出式日历中单击/选择日期,该如何处理? - DateTimePicker: How will I handle if the user clicked/selected date in the popup calendar or not? 如何将所选日期从AJAX日历控件传递到存储过程 - How to pass selected date from AJAX calendar Control into stored procedure 从月份日历控件中删除选定的日期 - Remove selected date from a month calendar control C#Web表单-寻找从日历中选择日期之后的月份的第一个星期一的日期 - C# web form - Looking to get the date of the first monday of the month after the selected date from the calendar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM