簡體   English   中英

輸入內容未提交更改表格

[英]Input does not submit the form on change

我對“更改時”輸入有疑問。 它應該做的是單擊該按鈕時會顯示日期選擇器,但是當您選擇要提交的日期時,輸入更改功能將不起作用。 請在下面運行代碼段。

 if (top.location != location) { top.location.href = document.location.href; } $(function() { window.prettyPrint && prettyPrint(); $('#dp1').datepicker({ format: 'yyyy-mm-dd' }); $('#dpYears').datepicker(); $('#dpMonths').datepicker(); }); 
 <link href="http://www.eyecon.ro/bootstrap-datepicker/css/bootstrap.css" rel="stylesheet" /> <link href="http://www.eyecon.ro/bootstrap-datepicker/css/datepicker.css" rel="stylesheet" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="http://www.eyecon.ro/bootstrap-datepicker/js/bootstrap-datepicker.js"></script> <div data-date-format="yyyy-mm-dd"> <form id="date" method="POST" action="index.php"> <input type="text" name="date" class="span2" value="2016-08-07" id="dp1" style="text-align: center; width: 50%; background-color: #5a95f5; border: none;"> </form> </div> <script> $('input[id="dp1"]').change(function() { $('#date1').submit(); }); </script> 

問題是選擇日期時您的輸入不會觸發change()函數。 您可以做的是在datepicker中使用事件,在這種情況下為changeDate

 if (top.location != location) { top.location.href = document.location.href; } $(function() { window.prettyPrint && prettyPrint(); $('#dp1').datepicker({ format: 'yyyy-mm-dd' }); $('#dpYears').datepicker(); $('#dpMonths').datepicker(); }); 
 <link href="http://www.eyecon.ro/bootstrap-datepicker/css/bootstrap.css" rel="stylesheet" /> <link href="http://www.eyecon.ro/bootstrap-datepicker/css/datepicker.css" rel="stylesheet" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="http://www.eyecon.ro/bootstrap-datepicker/js/bootstrap-datepicker.js"></script> <div data-date-format="yyyy-mm-dd"> <form id="date" method="POST" action="index.php"> <input type="text" name="date" class="span2" value="2016-08-07" id="dp1" style="text-align: center; width: 50%; background-color: #5a95f5; border: none;"> </form> </div> <script> $('#dp1').on('changeDate', function () { console.log('Date Selected') }) </script> 

很簡單,您可以使用以下代碼:

$('#input-date')
.datepicker()   
.on('changeDate', function(e){    
    $('#formID').submit();
});

暫無
暫無

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

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