使用 JQuery Datepick 在选择上发布表单 [英] Post form on select with JQuery Datepick
问题描述
我有一个日历,我只显示某些日期可用,其余日期禁用.我得到了我所有的日期并组成了我的日历,它显示没有问题
I have a calendar I display with only certain dates available and the rest disabled. I get all my dates and make up my calendar and it displays without problem
<script type="text/javascript">
$(function() {
$.post('/jreqlib',
{ Action: 'GetDates',
}, function(data) {
var myNewDates = new Array;
for (var x = 0; x < data['validPubDates'].length; x++) {
myNewDates.push(data['validPubDates'][x]);
}
var myValidDates = new Array;
for (var x = 0; x<data['validPubDates'].length; x++) {
var theDate = data['validPubDates'][x];
myValidDates.push(theDate);
}
$('#inlineDatepicker').datepick({
multiSelect: 999,
minDate : '-14d',
maxDate : '+2y',
onSelect : function (dateText, inst) {
//alert("Clicked');
//$("#FormId").click();
$(this).parent('form').submit();
},
onDate : getAllowed(myValidDates),
}).datepick('setDate',myNewDates);
},
'json');
});
</script>
问题是我想在单击日期时提交表单(而不是通过 ajax).我找到了一堆帖子,但似乎没有一个起作用.如果我取消对 "alert" 的注释,那么我会看到 "clicked" 消息,但不会看到 $("#FormId").click();(是的,表单中有一个 id="FormId")
或 $(this).parent('form').submit();
或其他 2 或 3 种方式我发现要做表单提交.
The issue is I want to submit the form (not via ajax) when a date is clicked. I found a bunch of posts but none of them seemed to work. If I un-comment that "alert" then I see the "clicked" message but neither the $("#FormId").click(); (yes the form has a id="FormId" in it)
or $(this).parent('form').submit();
or the 2 or 3 other ways I found to do the form submit.
我在点击时到达那里,如果取消评论就会触发警报,为什么表单不会提交?
I'm getting there on the click, the alert will fire if un-commented, how come the form won't submit?
(顺便说一句 - 我没有发布 getAllowed 函数,因为我认为它不相关,但如果需要我会发布)
(BTW - I didn't post the getAllowed function as I didn't think it relevant but I will if needed)
TIA
推荐答案
尝试给表单一个 id,然后通过 jquery id 选择器调用 submit:
Try giving the form an id and then calling submit via an jquery id selector:
<form id="myFormID">
...
$('#inlineDatepicker').datepick({
multiSelect: 999,
minDate : '-14d',
maxDate : '+2y',
onSelect : function (dateText, inst) {
$('#myFormID').submit(); // <-- SUBMIT LIKE THIS
},
onDate : getAllowed(myValidDates),
}).datepick('setDate',myNewDates);
这篇关于使用 JQuery Datepick 在选择上发布表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!