如何在jQuery中动态添加锚点/href [英] How to dynamically add anchor/href in jQuery
本文介绍了如何在jQuery中动态添加锚点/href的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是jQuery的新手,我正尝试将我所有的电话类转换为具有href的锚点:
Im new to jQuery and i'm trying to convert all my phone class to have an anchor with an href:
我有什么
<div class="phone">111-111-1111</div>
<div class="phone">666-555-4444</div>
我想要的
<div class="phone"><a href="tel:111-111-1111">111-111-1111</a></div>
<div class="phone"><a href="tel:666-555-4444">666-555-4444</a></div>
我正在尝试做这样的事情,但是我很迷茫:
I am trying to do something like this, but I am pretty lost:
$('.phone').each(function(){
$(this).wrapInner('<a name="???' + $(this).html() + '" />');
});
推荐答案
我认为仅在您的问题中存在解决方案...
I think solution is there in your question only...
看看这个.
$('.phone').each(function(){
$(this).wrapInner('<a href="tel:' + $(this).html() + '" />');
});
FIDDLE 希望这就是您想要的.
FIDDLE Hope this is what you want.
这篇关于如何在jQuery中动态添加锚点/href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文