2015-03-18 36 views
-1

如果我有这样的对象字面:生成HTML链接的电子邮件地址

{"name":"James","email":"[email protected]"} 

...我怎么打印出来的HTML链接到该电子邮件地址?输出应该是这样的:

<a href="mailto:[email protected]">James</a> 
+0

你想用普通的JavaScript,jQuery的,还是其他什么东西?或者是发生在服务器端? – 2015-03-19 00:20:34

+0

**你到目前为止尝试过什么?**堆栈溢出不是某种代码写入服务。发布你已经*试过*,而不是要求它被写*为*你。 – esqew 2015-03-19 00:23:43

回答

1

你可以尝试这样的事:

var contact = {"name": "James", "email":"[email protected]"}; 
var href = "mailto:" + contact.email; 

var link = document.createElement('a'); 

link.setAttribute("href", href); 
link.innerHTML = contact.name; 

document.body.appendChild(link); 

http://jsbin.com/qimosu/1/