簡體   English   中英

如何在jQuery更改中獲取日期選擇器的值

[英]How to get the value of date picker on change in jquery

我需要獲取onchange日期的值,

這是代碼

<div class="input-daterange" data-date-format="dd/mm/yyyy">

       <label>Date </label>                                                       
<input id="value_date"  class="form-control"  name="start" type="text" />                                                                              
</div>

這是我的jQuery

$('#value_date').change(function() {{

    var valuefirstone = document.getElementById('#value_date').value;
    alert(valuefirstone);
}
</script>

Onchange函數未調用,我只是在更改時創建警報,但它不起作用

嘗試這個 ;

$('#value_date').datepicker().on('changeDate', function (ev) {
    var valuefirstone = $(this).val();
    alert(valuefirstone);
});

刪除.datepicker()如果已完成)

最好是使用jquery內置函數內部jquery context 另外,從日期選擇器獲取值的jquery change function語法和javascript代碼是錯誤的。

將您的jquery change函數更改為:

$(document).ready(function(){

    $('#value_date').change(function() {

        var valuefirstone = $(this).val();//use jquery built in functions
        alert(valuefirstone);

    });

});

確保用文檔就緒fn包裝了更改功能

您可以輕松地使用以下代碼:

 $("#value_date").on('change', function(event) {
   event.preventDefault();
   alert(this.value);
  /* Act on the event */
  });
$('#value_date').change(function() {{

    alert($('#value_date').val());
}
</script>

注意這兩個更改-刪除get by id並更改為.val()。

暫無
暫無

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

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