代码之家  ›  专栏  ›  技术社区  ›  alexkodr

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

  •  2
  • alexkodr  · 技术社区  · 7 年前

    我试图使用append在jqueryuidatepicker中动态插入一些html,其中包含div,但就是不能让它工作。

    $("#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 回复  |  直到 7 年前
        1
  •  2
  •   Mohammad DefenestrationDay    7 年前

    似乎您需要等到datepicker内容插入到框中之后才能使用 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">