尝试在jQuery datepicker div中插入一些HTML



我正在尝试使用append在jQuery ui datepicker中动态插入一些包含div的html,但无法使其工作。

这是我到目前为止得到的:

$("#dt1").datepicker({
beforeShow:function(textbox, instance){
$("#ui-datepicker-div").append("<b>Appended text</b>");
}
});

尝试让它工作,以便像这样预览:

<div id="ui-datepicker-div" class="ui-datepicker">
<b>Appended text</b>

似乎您需要等到日期选择器内容插入框中,以便您可以使用setTimeout()来完成这项工作。

$("#dt1").datepicker({
beforeShow:function(){
setTimeout(function(){
$("#ui-datepicker-div").append("<b>Appended text</b>"); 
}, 10);
}
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<input type="text" id="dt1">

最新更新