[英]Add condition comment in JavaScript
我在Outlook中为电子邮件呈现圆形按钮时遇到问题。 我想尝试一下VML
。
<!--[if mso]>
<v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="http://www.EXAMPLE.com/" style="height:40px;v-text-anchor:middle;width:300px;" arcsize="10%" stroke="f" fillcolor="#d62828">
<w:anchorlock/>
<center style="color:#ffffff;font-family:sans-serif;font-size:16px;font-weight:bold;">
Button Text Here!
</center>
</v:roundrect>
<![endif]-->
<!--[if !mso]> <!-->
我的电子邮件是用JavaScript生成的。 如何在JavaScript中创建条件注释?
编辑1:使用document.createComment
:
var c = document.createComment("My personal comments");
似乎没有帮助,因为它添加了以下注释:
<!--My personal comments-->
虽然注释中包含if
, endif
等。 如何完成将这些条件添加到评论中?
您可以使用Document.createComment()创建注释节点,然后将其附加到dom节点。
//make a comment var comment = document.createComment("I am a generated comment"); //append it to an element document.querySelector("html").append(comment);
所以就你而言...
var comment = document.createComment('[if mso]> <v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="http://www.EXAMPLE.com/" style="height:40px;v-text-anchor:middle;width:300px;" arcsize="10%" stroke="f" fillcolor="#d62828"> <w:anchorlock/> <center style="color:#ffffff;font-family:sans-serif;font-size:16px;font-weight:bold;"> Button Text Here! </center></v:roundrect><![endif]');
document.querySelector("html").append(comment);
...应该可以解决问题
请注意,尽管条件注释可能看起来像2个特殊注释,并且其中一些html之间实际上只是一个常规HTML注释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.