簡體   English   中英

如何顯示中的jQuery datepicker值 <p> 使用innerHTML標記

[英]How to display jquery datepicker value in <p> tag using innerHTML

我試圖將日期選擇器添加到我的網頁中,以顯示用戶從日期選擇器插件中選擇的日期,並將其顯示在日歷圖標旁邊的<p>標記中。 當前,我可以顯示日期選擇器,但是當用戶選擇日期時,什么也沒有發生。 我試圖使用innerHTML檢索所選日期並顯示它。

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Test</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
    <!-- Bootstrap 3.0 -->
    <link rel="stylesheet" href="main.css">
    <!-- main CSS -->
    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
    <!-- JQuery CSS -->
</head>

<body>
<header>
    <div class="content-container">
        <div class="date-section">
            <div class="container">
                <div class="date-scroll">
                    <input type="hidden" id="datepicker">
                    <p id="date-fill"></p>
                </div>
            </div><!-- container -->
        </div><!-- date-section -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="js/myscript.js"></script>
<script>
    $("#datepicker").datepicker({
        showOn: "button",
        buttonImage: "http://hastypudding.org/assets/images/icon-calendar-blue.png",
        buttonText: "Open Calendar",
        buttonImageOnly: true,
        inline: true,
        onSelect: function(){
            var day1 = $("#datepicker").datepicker('getDate').getDate();                 
            document.getElementById("date-fill").innerHTML = day1.getDate();
        }
    });

</script>

</body>
</html>

改用此代碼

onSelect: function(){
    var day1 = $("#datepicker").datepicker('getDate');
    document.getElementById("date-fill").innerHTML = day1;
}

嘗試這個:

onSelect: function(dateText, inst) { 
      var dateAsString = dateText; //the first parameter of this function
      var dateAsObject = $(this).datepicker( 'getDate' ); //the getDate method
      $("#date-fill").html(dateAsObject)
   }

暫無
暫無

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

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