在Wordpress中,添加< span>标记所有链接 [英] Wordpress, add a <span> tag to all links
本文介绍了在Wordpress中,添加< span>标记所有链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在Wordpress网站上撰写博客文章时,我想在所有锚定标记中动态添加一个span标记,其数据属性与锚定标记具有相同的值.
When I write a blog post on my Wordpress site, I want do dynamically add a span-tag inside all the anchor tags, with a data-attribute that has the same value as the anchor tag.
示例
我在Wordpress中写的内容:
What I write in Wordpress:
<p>Some text with <a href="#">a link in it</a></p>
产生的东西:
<p>Some text with <a href="#"><span data-title="a link in it">a link in it</span></a>
如何使用jQuery或PHP?
How can you do this with jQuery or PHP?
推荐答案
jQuery和wrapInner()也可以:
jQuery and wrapInner() works also:
<p>Some text with <a class="generate_span" href="#">a link in it</a></p>
<script>
$('.generate_span').each(function(){
$(this).wrapInner('<span data-title="'+($(this).attr('href'))+'"></span>');
});
</script>
这篇关于在Wordpress中,添加< span>标记所有链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文