[英]Jquery datepicker execute function on load
I have the following script that works fine: 我有以下工作正常的脚本:
$(function() {
$( "#datepicker" ).datepicker
(
{
altField: '#sheetid',
onSelect: function load() {
$(document).ready(function() {
$.ajax({
type: 'POST',
url: 'test2.php',
data: {sheetid: $('#sheetid').val()},
success: function(data)
{
$("#contentz").html(data);
}
});
});
},
firstDay: 1});
}
);
The script loads data in a div based on the selected date from an inline jq datepicker. 该脚本根据从内联jq日期选择器中选择的日期将数据加载到div中。 But I can't seem to succeed on making it work for the default date, when the page first loads. 但是,当页面首次加载时,我似乎无法成功使它在默认日期生效。 I've tried: 我试过了:
$("#datepicker").load(function() {
$(document).ready(function() {
$.ajax({
type: 'POST',
url: 'test2.php',
data: {sheetid: $('#sheetid').val()},
success: function(data)
{
$("#contentz").html(data);
}
});
}
})
but that doesn't seem to work either. 但这似乎也不起作用。 Any suggestions? 有什么建议么?
I would do it like this: 我会这样做:
$(document).ready(function() {
$("#datepicker").load(function() {
$.ajax({
type: 'POST',
url: 'test2.php',
data: {sheetid: $('#sheetid').val()},
success: function(data)
{
$("#contentz").html(data);
}
});
});
});
it makes no sense to bind something to the document.ready event on datepicker.load. 将某些东西绑定到datepicker.load上的document.ready事件没有任何意义。 You can do what you want directly there. 您可以直接在那做您想做的事。
As far as I see, there is nothing asynchronous here. 据我所知,这里没有异步。 So just do it consecutively: 因此,只需连续执行:
$(function() {
$("#datepicker").datepicker({});
// your function with ajax call here
console.log( $("#ui-datepicker-div").length );
});
This effectively logs "1". 这有效地记录为“ 1”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.