我有图像列表。我想在单击时将数据属性复制到剪贴板。我现在拥有的是警报数据属性。我尝试了复制命令,但它不起作用(不要复制任何东西)。拜托,有人可以帮我吗?
var emojiImages = document.getElementsByClassName('emoji-image');
for(var i=0; i< emojiImages.length; i++){
emojiImages[i].onclick = function(){
var a = this.getAttribute('data-emoji');
alert(a);
}
}
<ul style="display: block; column-count: 8;"><li>:first:<img class="emoji-image" src="https://www.gravatar.com/avatar/086495a58faa8219a2640ad87325a12d?s=48&d=identicon&r=PG&f=1" width="36" height="36" data-emoji=":first:"></li><li>:second:<img class="emoji-image" src="https://www.gravatar.com/avatar/086495a58faa8219a2640ad87325a12d?s=48&d=identicon&r=PG&f=1" width="36" height="36" data-emoji=":second:"></li></ul>