如果我有这个对象文字:
{"name":"James","email":"123@yahoo.com"}
...如何打印出该电子邮件地址的HTML链接?输出应该是这样的:
<a href="mailto:123@yahoo.com">James</a>
答案 0 :(得分:1)
您可以尝试这样的事情:
var contact = {"name": "James", "email":"123@yahoo.com"};
var href = "mailto:" + contact.email;
var link = document.createElement('a');
link.setAttribute("href", href);
link.innerHTML = contact.name;
document.body.appendChild(link);