javascript - 将自定义日期格式添加到 JSP html 代码
问题描述
<td>${item.actionDate}</td>
接收格式为 2019-11-17 (yyyy/mm/dd) 的日期。我想将此格式编辑为 dd/mm/yyyy。我发现我可以使用下面的方法为这个 td 元素提供格式。
<script type="text/javascript">
$(document).ready(function() {
$('#serial_no_date_format').datepicker({
format: 'dd/mm/yyyy'
});
})
</script>
我知道上面的代码片段是正确的,因为它在我的代码的其他部分中工作。但是,我无法将此日期格式传递给带有 id 参考的 td.item.actionDate 元素。
我的整体在下面
<div class="tab-pane fade active in" id="tab_1_1">
<div class="row">
<div class="col-md-12">
<table class="table table-striped table-bordered table-hover order-column">
<thead>
<tr>
<th>Sevkiyat No</th>
<th>Operator</th>
<th>İşlem Tarihi</th>
<th>İşlem</th>
<th>Lokasyon</th>
</tr>
</thead>
<tbody>
<c:forEach items="${shipmentTransferHistoryList}" var="item">
<tr>
<td>${item.shipmentDetailId}</td>
<td>${item.operator}</td>
<td>${item.actionDate} id="serial_no_date_format"</td>
<td>${item.shipmentStatus.alias}</td>
<td>${item.actionLocation}</td>
</tr>
</c:forEach>
</tbody>
</table>
<script type="text/javascript">
$(document).ready(function() {
$('#serial_no_date_format').datepicker({
format: 'dd/mm/yyyy'
});
})
</script>
</div>
</div>
</div>
我怎样才能做到这一点?
解决方案
您的 id 应设置在标签内。
<td>${item.actionDate} id="serial_no_date_format"</td>
改成这个
<td id="serial_no_date_format">${item.actionDate} </td>
请注意,您可能会遇到重复 id 的问题,因此如果可能,请将其更改为 class。
编辑
我想这会解决你的问题。
var date = $('#serial_no_date_format').datepicker({format: 'dd/mm/yyyy'}).val();
$('#serial_no_date_format').val(date);
推荐阅读
- c++ - 如何在 OpenCV 窗口中获取有关图像缩放部分的信息?
- git - 跨平台 mkdir?
- php - Paysify 情绪 api 返回 null
- c# - 为什么 grpc 在 IIS 上以 403 响应
- javascript - 当日期值为空时,在 HTML 页面中显示自定义文本
- android - 从 Firebase 传感器数据发送通知警报
- reactjs - 如何覆盖 Material UI 自动完成选项的样式或 CSS?
- amazon-web-services - 如果我的安全组在端口 22 上允许 TCP 并且没有网络访问控制列表,为什么我不能通过 SSH 连接到我的 EC2 实例?
- java - 如何获取类整数的最基本比较器的实例
- typescript - 用于安全阵列访问的 TS 配置