簡體   English   中英

如何在標簽和文本框中顯示日期選擇器值

[英]How to show date picker value in a label and textbox

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

我正在使用此功能

它的輸入框是

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

請幫我吧啦

習慣於此代碼

演示版

 <!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" ));

javascript獲取價值

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

並分配給lable

你必須喜歡

 $(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> 

請檢查文件

你也可以不用onSelect就可以得到它

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

嘗試這個

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

在我看來,您想在單擊圖標時觸發日期選擇器。 在此處檢查文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM