【问题标题】:Passing value from Calendar Picker to textbox将值从日历选择器传递到文本框
【发布时间】:2013-12-16 06:56:29
【问题描述】:

大家好,我无法从日历选择器中获取价值。 我想从日历中选择一个日期(ID 为Date_of_Birth)并将日期说12/11/2013 分配给文本框txtDate

我该怎么做?我的代码如下

<!DOCTYPE HTML>
<html>

    <head>

    </head>
    <body>

<form name="myForm" action="displayDate.html" method="post">

Date of Birth: < script type="text/javascript" src="http://www.snaphost.com/jquery/Calendar.aspx?dateFormat=dd/mm/yy" name="Date_of_Birth" id="Date_of_Birth"></script><br>

           <input type="text" id="txtDate" name="txtDate"

            <input type="submit" value="Submit">
        </form>
    </body>
</html>

【问题讨论】:

    标签: html date


    【解决方案1】:

    第一个问题是您没有正确包含“http://www.snaphost.com/jquery/Calendar.aspx?dateFormat=dd/mm/yy”。此脚本会创建一个日历,但不会按照您希望的方式工作。从代码中我可以看到这个库使用了 jQueryUI。

    不要使用 aspx url,而是单独包含 jQueryUI 库:

    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    
    <form name="myForm" action="displayDate.html" method="post">
    
        Date of Birth: <input type="text" id="txtDate" name="txtDate"/>
        <input type="submit" value="Submit"/>
    
    </form>
    

    要将日期选择器绑定到 txtDate 使用:

      $(function() {
        $( "#txtDate" ).datepicker();
      });
    

    查看工作示例:http://jsfiddle.net/2zdgz/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-01
      • 1970-01-01
      • 2015-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多