简体   繁体   中英

How to show date picker value in a label and textbox

$("#datepicker").datepicker();

I am using this function

and its box of input is

<input type="text" id="datepicker" name="fulldate" class="form-control wid-100"> <span id="#dpicker_name"></span>

Please help me in it friends

used to this code

Demo

 <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery UI Datepicker - Default functionality</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <link rel="stylesheet" href="/resources/demos/style.css"> <script> $(function() { $( "#datepicker" ).datepicker(); }); $(document).ready(function(){ $('#datepicker').on('change', function(){ var dateThis = $(this).val(); $('#dpicker_name').text(dateThis); }); }); </script> </head> <body> <p>Date: <input type="text" id="datepicker"> <span id="dpicker_name"></span></p> </body> </html> 

尝试这个。

$("#dpicker_name").text($( "#datepicker" ).datepicker( "getDate" ));

Get value in javascript as

var date = $(".datepicker").val();

and assigned it to the lable

You have to do like

 $(document).ready(function(){ $("#datepicker").datepicker({ onSelect: function(dateText, inst) { $("#dpicker_name").html(dateText); } }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.css"> <input type="text" id="datepicker" name="fulldate" class="form-control wid-100"> <span id="dpicker_name"></span> 

Please check Documentation

Also you can get it without onSelect like

$("#datepicker").datepicker("getDate");

Try this

   $( "#datepicker" ).datepicker({
      showOn: "button",
      buttonImage: "images/calendar.gif",
      buttonImageOnly: true,
      buttonText: "Select date"
   });

Seems to me you want to trigger the datepicker on click of icon. Check the docs here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM