我正在尝试用
标签替换以下字符串的第二个 / ,以便年份将换行
<span class="post-date">15/03/2024</span>
有没有办法用 html 标签替换字符(或一般的字符串),比如
<br>
标签?
我认为这会起作用
<span class="post-date" id="post-date">15/03/2024</span>
<script>
var dateString = document.getElementById("post-date").innerHTML;
var secondSlashIndex = dateString.indexOf('/', dateString.indexOf('/') + 1);
var firstPart = dateString.substring(0, secondSlashIndex);
var secondPart = dateString.substring(secondSlashIndex + 1);
var replacedString = firstPart + "<br>" + secondPart;
document.getElementById("post-date").innerHTML = replacedString;
</script>