我有以下,我想删除时间,例如12:30 div。做这件事最好的方法是什么?内容是动态的。这是我试过的Fiddle
<div class="jsmatchdate">
11-08-2018 12:30
</div>
发布于 2018-08-05 04:34:33
使用JQuery:
$('.jsmatchdate').text( function (_,txt) {
return txt.split(' ')[0];
})
说明:我们用‘’(空字符)拆分文本
split函数返回'11-08-2018','12:30‘的数组,我们需要索引为0的第一部分。
发布于 2018-08-05 04:31:45
如果您想使用切片,那么您可以尝试使用jQuery命令。
$('.jsmatchdate').text(function (_,txt) {
return txt.slice(0, 11);
});
这样做的目的是获取div中的文本并返回所需的长度,例如11-08-2018
发布于 2018-08-05 04:32:09
let b = $(".jsmatchdate").text().split(' ')[0];
$(".jsmatchdate").html(b);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="jsmatchdate">
11-08-2018 12:30
</div>
https://stackoverflow.com/questions/51689267
复制相似问题