0

我的 html 代码看起来像这样

<a class="wsl_connect_with_provider" title="Connect with Facebook" data-provider="Facebook">
<img src="/assets/img/facebook.png">
</a>
<a class="wsl_connect_with_provider" title="Connect with Twitter" data-provider="Twitter">
<img src="/assets/img/twitter.png">
</a>

我想用这样的img方式title替换jquery

<a class="wsl_connect_with_provider" title="Connect with Facebook" data-provider="Facebook">
    Connect with Facebook
    </a>
    <a class="wsl_connect_with_provider" title="Connect with Twitter" data-provider="Twitter">
    Connect with Twitter
    </a>

有人可以告诉我该怎么做吗?

4

3 回答 3

2
$.each($('img'), function(){
  $(this).replaceWith('<span>'+$(this).attr('title')+'</span>');
});
于 2013-09-29T00:33:41.913 回答
1

这应该有效:

$('a.wsl_connect_with_provider').each(function(){
  $(this).text($(this).prop('title'));
});

演示在这里

于 2013-09-29T00:36:46.437 回答
1
$('.wsl_connect_with_provider img').each(function () {
    $(this).replaceWith(
        $(this.parentNode).attr('title')
    );
});
于 2013-09-29T00:40:14.837 回答