我想在我的内容区域中找到所有时间码并围绕它建立一个简单的链接,因此我可以在Wordpress Mediaelement上跳转到特定的时间码。
我该怎么做,这样最终看起来像:
<div class="timecodes">
<li>
**<a class="go-to-time">**15:30**</a>** "Title"
</li>
</div>
最佳答案
我自己弄清楚了,这是我的解决方案:
var str=document.getElementById("timecodes").innerHTML;
var n=str.replace(/[0-9][0-9][:][0-9][0-9]/gi,function myFunction(x){return "<a class='go-to-time'>" + x + "</a>";});
document.getElementById("timecodes").innerHTML=n;