如何在javascript中的document.write()方法中添加类

如何在javascript中的document.write()方法中添加类,javascript,Javascript,我正在document.write中添加一个类,但没有显示,下面是我的代码 new_window = open("","hoverwindow","width=600,height=300,left=10,top=10"); new_window.document.open(); new_window.document.write("<li>Dowload <a href=www.anylink.com class='help'></a></li>

我正在document.write中添加一个类,但没有显示,下面是我的代码

new_window = open("","hoverwindow","width=600,height=300,left=10,top=10");
new_window.document.open();
new_window.document.write("<li>Dowload <a href=www.anylink.com class='help'></a></li>");
new_window=open(“,”悬停窗口“,”宽度=600,高度=300,左侧=10,顶部=10”);
新建_window.document.open();
新建窗口。文档。写入(“
  • Dowload
  • ”;

    “帮助”是在我的css文件中定义的。以上语法是否适用于该类。

    如@FrédéricHamidi sayd:

    new_window = open("","hoverwindow","width=600,height=300,left=10,top=10");
    new_window.document.open();    
    new_window.document.write("<li>Dowload <a href='www.anylink.com' class='help'></a></li>");
    
    new_window=open(“,”悬停窗口“,”宽度=600,高度=300,左侧=10,顶部=10”);
    新建_window.document.open();
    新建窗口。文档。写入(“
  • Dowload
  • ”;
    您的锚是空的:

    <li>Dowload <a href=www.anylink.com class='help'></a></li>
                                                     ^--------
    
    下载 ^-------- 改为:

    <li><a href="www.anylink.com" class='help'>Dowload</a></li>
                                               ^^^^^^^-------
    
  • ^^^^^^^-------
    不要使用document.write-它可能会给您带来问题:


    还有其他方法可以使用JavaCScript-将HTML注入页面。innerHTML就是一个很好的例子。像jQuery这样的JavaScript库也有很多选项。

    问题中的标记无效。
    href
    属性的值周围应该有引号。您的问题是什么?帮助类已创建,但css文件可能不存在于您的新浏览器窗口中。它存在,如果我在某些td中使用该类,td将受到影响,但不在文档中。write().你的新浏览器窗口中是否有某个
    td
    ?该帮助类有一个图像,但该图像未显示。如果我在HTML中的任何属性中应用这个类,它都可以工作,但在document.write()中没有