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