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

时间:2018-10-10 09:25:54

标签: jquery html jquery-ui-datepicker

我正在尝试使用append在包含div的jQuery ui datepicker中动态插入一些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>

1 个答案:

答案 0 :(得分:2)

似乎您需要等到日期选择器内容插入框中后,才能使用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">