简体   繁体   English

innerHTML 不起作用,为什么?

[英]innerHTML doesn't work, why?

I want set 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>';

How replace this span content?如何替换这个 span 内容?

You haven't closed your href attribute with a double-quote.你还没有用双引号关闭你的 href 属性。

href="mailto:'+email+'>

Should be应该

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

You are missing a closing " the code should read:你错过了一个关闭“代码应该是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM