Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何将属性电子邮件字符串添加到ahref标记中?_Html_Css - Fatal编程技术网

Html 如何将属性电子邮件字符串添加到ahref标记中?

Html 如何将属性电子邮件字符串添加到ahref标记中?,html,css,Html,Css,我有一本书 <img class="img_thumb" src="images/cropped9.jpg" author-email="huizhong@hotmail.com"> 和 <a class="email" href="mailto:">huizhong@hotmail.com"</a> 我想做一个电子邮件链接,是可点击的,我阅读和理解我只是要做的事 <a href="mailto:huizhong@hotmail.com"&g

我有一本书

<img class="img_thumb" src="images/cropped9.jpg" author-email="huizhong@hotmail.com">

<a class="email" href="mailto:">huizhong@hotmail.com"</a>

我想做一个电子邮件链接,是可点击的,我阅读和理解我只是要做的事

<a href="mailto:huizhong@hotmail.com"></a>

但是我的电子邮件具有img属性,因此我想知道如何将其添加到href

谢谢

您可以使用
img
元素来获取
作者电子邮件
属性并设置
a
元素的
href
属性:


或者为
a
标记使用
背景图像
提取
作者电子邮件
的值,并使用jqueryrap将img标记与a标记:包装
var image = document.getElementsByClassName('img_thumb')[0];

var a = document.getElementsByClassName('email')[0];
a.href = "mailto:" + image.getAttribute('author-email');

console.log(a)