我的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>
有人可以告诉我该怎么做吗?
答案 0 :(得分:2)
$.each($('img'), function(){
$(this).replaceWith('<span>'+$(this).attr('title')+'</span>');
});
答案 1 :(得分:1)
这应该有效:
$('a.wsl_connect_with_provider').each(function(){
$(this).text($(this).prop('title'));
});
演示here
答案 2 :(得分:1)
$('.wsl_connect_with_provider img').each(function () {
$(this).replaceWith(
$(this.parentNode).attr('title')
);
});