0

I'd like to be able to see the date selected with a Metro UI CSS datepicker using javascript. Eventually this data would be used for building a JSON object to be sent in an AJAX request. For now though, I'd be happy just to see it in a browser alert message.

Here's the datepicker control: http://metroui.org.ua/datepicker.html Notice the second datepicker has a default value.

How can I use the browser console to get that default value into an alert message? Surely I'm missing something obvious, but I've had no luck doing things like checking "val()" of the input element, etc.

4

2 回答 2

2

我刚刚找到了一个小解决方法(又快又脏):给 in 一个唯一的 Id <input type="text"...<div class="input-control text"...然后让 JQuery 来创造魔法!这是代码:

<div id="dpContainer" class="input-control text">
    <input id="inputToRead" type="text">
    <button class="btn-date"></button>
</div>

<script>
    function getDPValue(){
      var selectedDate = $('#inputToRead').val();
      return selectedDate;
    }
</script>

我知道它有点脏,也许你可以从http://metroui.org.ua/calendar.html函数中得到一些有用的提示。

更快更脏:

<script>
  function getDPValue(){
    return $('#dpContainer').children('input[type=text]').val();
  }
</script>

HTH,斯特凡诺。

于 2014-12-10T10:27:20.240 回答
1

日期选择器内部有一个日历控件。您可以获取运行.calendar('getDate')的日历控件的选定日期。然后让 JQuery 完成他的工作并到达datepicker中的日历控件。

<div id="myDate" class="input-control text" data-role="datepicker" data-preset="2016-01-01">
    <input type="text">
    <button class="button"><span class="mif-calendar"></span></button>
</div>

<script>
    function getMyDate(){
        return $('#myDate .calendar').calendar('getDate');
    }
</script>

<button class="button" onclick="alert(getMyDate())">Show My Date</button>   
于 2016-02-10T15:50:27.613 回答