javascript - Timepicker 没有显示动态条目的焦点?
问题描述
我有一个调度程序,允许用户选择时间。使用 Ajax 为每一行添加一个计划时间,在该行中他们可以选择日期、开始时间和结束时间。日期选择器似乎工作但时间选择器没有出现。
我尝试在我的 jquery 中使用document
而不是body
选择器,但没有用。
$(document).on('focus', ".timepickerInput", function () {
$(this).timepicker({
timeFormat: "hh:mm tt",
interval: 5,
dropdown: true,
scrollbar: true
});
});
日期选择器:
$('body').on('focus', ".datepickerInput", function () {
$(this).datepicker({
controlType: "select",
});
});
这是当前时间选择器的代码:
$('body').on('focus', ".timepickerInput", function () {
$(this).timepicker({
timeFormat: "hh:mm tt",
interval: 5,
dropdown: true,
scrollbar: true
});
});
这是添加新行的代码:
$("#addScheduleButton").click(function () {
var nextIndex = $(".pendingScheduleRow").length;
$.ajax({
url: "/Admin/AddScheduleItem",
type: 'POST',
data: {
index: nextIndex
},
success: function (results) {
$("table#scheduleTable tbody").append(results);
$("#savePendingButton").show();
}
});
});
这是 HTML 表单:
<form asp-action="SetSchedule" asp-controller="Admin" method="post" id="addEventForm">
<table id="scheduleTable">
<thead>
<tr>
<th>Date</th>
<th>Start Time</th>
<th>End Time</th>
<th></th>
</tr>
</thead>
<tbody></tbody>
</table>
<br />
<button id="addScheduleButton" type="button">Add Schedule Time</button>
<button id="savePendingButton" type="submit" style="margin-left:1em" hidden>Save</button>
</form>
我希望时间选择器在动态附加到 html 时为添加的每一行工作。
解决方案
推荐阅读
- json - helm -- 为 datadog/hazelcast 设置 json 值
- asp.net-mvc - blazor.server.js 在我的 Blazer Web App 项目中破坏了我的脚本文件
- php - PHP中包含文件的致命未定义函数错误
- python - 无法使用 xmlschema.from_json
- c# - 如何使用 ajax 将带有文件的每一行发布到控制器
- java - 如何在邮递员中调用@PreAuthorize ("#oauth2.hasScope('mstps:mysourcetest')")
- powerbi - Power BI 使用折线图绘制文本事件
- r - 在数据框中的多列中计数“1”
- python - Python初学者坚持从包函数的输出创建一个新的熊猫列
- php - 使用 PHP 从 URL 获取 JSON 对象