jQuery UI Datepicker Inline - 单击提交表单

标签 jquery jquery-ui jquery-plugins jquery-ui-datepicker

我试图在日期选择器上单击日期时提交表单。我已成功提交,但无法将所选日期传递到表单的隐藏字段。因此,表单已提交,但日期未发送(

我确信这一定很简单,但我对 js 没有经验,所以任何帮助都是值得赞赏的。

代码如下:

<script type="text/javascript">
  $(document).ready($(function(){

    var $hiddenInput = $('#hiddenFieldID');

    $('#datepicker').datepicker({ inline: true })
     .bind('click', function(){ $('#myFormID').submit();})
     .bind('hiddenFieldID',function(e, hiddenFieldID, $td) { $hiddenInput.val(hiddenFieldID.asString()); });
      }));
 </script>

<div id="datepicker"></div>

<form id="myFormID" action="index.php" method="GET">
<input type="hidden" name="date" id="hiddenFieldID" value="">
</form>

最佳答案

datepicker 实际上有一些选项可以帮助您完成此任务。请尝试以下操作:

$('#datepicker').datepicker({
    inline : true,
    altField : '#hiddenFieldID',
    onSelect : function(){
        $('#myFormID').submit();   
    }
});

altField: An input element that is to be updated with the selected date from the datepicker. Use the altFormat option to change the format of the date within this field. Leave as blank for no alternate field.

onSelect: Called when the datepicker is selected. The function receives the selected date as text and the datepicker instance as parameters. this refers to the associated input field.

访问完整的 API 以获取与 datepicker 相关的更多选项和事件:http://api.jqueryui.com/datepicker/

关于jQuery UI Datepicker Inline - 单击提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15005857/

相关文章:

jQuery 自动完成下拉框

jquery - 当您将鼠标悬停在导航项上时,nosotroshq.com 如何创建导航效果?

javascript - 如何在 jQuery 中声明这个函数? $(document).ready 不起作用

jquery - Laravel 中使用 AJAX 与数据库交互

jquery - 如何将 Bootstrap 中的下拉代码转换为悬停代码?

JqueryUI数据表设置recordsTotal

jquery - 滑入和滑出图像

jquery - 如何调整移动版wordpress网站的logo大小?

javascript - jQuery:如何在没有ajax的情况下单击链接后发布数据?

javascript - 单击标题外侧的跨度时如何打开 Accordion