innerHTML不工作,为什么?

innerHTML doesn't work, why?

本文关键字:为什么 工作 innerHTML      更新时间:2023-09-26

我想设置new in span,

var email ='ss@ww.net';
document.getElementById('spanEmail').innerHTML='<a class="f14 bold rose" href="mailto:'+email+'>'+email+'</a>';

but this way not working, but this working

document.getElementById('spanEmail').innerHTML='sample text>';

如何替换span内容?

你没有用双引号关闭你的href属性

href="mailto:'+email+'>
应该

href="mailto:'+email+'">

您缺少一个结束",代码应该是:

document.getElementById('spanEmail').innerHTML='<a class="f14 bold rose" href="mailto:'+email+'">'+email+'</a>';