[英]Add mailto: with jQuery?
<table id="here" border="1">
<tr><td>London</td><td>london@us.uk</td><td>aaa</td><td>aaa</td></tr>
<tr><td>Manchester</td><td>manchester@us.uk</td><td>aaa</td><td>aaa</td></tr>
<tr><td>Liverpool</td><td>liverpool@us.uk</td><td>aaa</td><td>aaa</td></tr>
<tr><td>Ipswich</td><td>ipswich@us.uk</td><td>aaa</td><td>aaa</td></tr>
</table>
是否可以添加鏈接mailto:對於帶有jQuery的電子郵件地址的第二列(不是修改HTML)? 如果有,怎么樣?
你可以用一個帶有mailto:
href: http : //jsfiddle.net/zwsMD/5/ a
元素替換每個第二個td
的內容。
$("#here td:nth-child(2)").each(function() {
var email = $(this).text();
// replace contents
$(this).html(
$("<a>").attr("href", "mailto:" + email).text(email)
);
});
你可以這樣做
$('td:nth-child(2)').each(function(){
var text = $(this).text();
var href = "mailto:"+text;
var $a = $('<a>', { href: href, text: text});
$(this).text('').append($a);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.