【问题标题】:Trying to insert some HTML inside jQuery datepicker div试图在 jQuery datepicker div 中插入一些 HTML
【发布时间】:2018-10-10 09:25:53
【问题描述】:

我正在尝试使用 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>

【问题讨论】:

    标签: jquery html jquery-ui-datepicker


    【解决方案1】:

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

    【讨论】:

    • 完美。有一种感觉可能是日期选择器同时触发。因此,设置超时非常有意义。谢谢
    猜你喜欢
    • 1970-01-01
    • 2019-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多