Javascript 写a<;部门>;使用document.write()的类

Javascript 写a<;部门>;使用document.write()的类,javascript,html,Javascript,Html,我正在尝试使用脚本中的document.write()编写div。我似乎可以写一个空白的div,但每当我向div添加一个类或任何属性时,它就不再写任何东西了 这就是我试图运行的代码 document.write("<div class="new_prod_box">"); document.write("<a href="details.html">"); document.write(x[i].getElementsByTagName("TITLE")[0].child

我正在尝试使用脚本中的document.write()编写div。我似乎可以写一个空白的div,但每当我向div添加一个类或任何属性时,它就不再写任何东西了

这就是我试图运行的代码

document.write("<div class="new_prod_box">");
document.write("<a href="details.html">");
document.write(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);
document.write("</a>");
document.write("<div class="new_prod_bg">");
document.write("<a href="details.html"><img src="images/thumb1.gif" alt="" title="" class="thumb" border="0" /></a>");
document.write("</div>");
document.write("</div>");
document.write(“”);
文件。填写(“”);
文件。填写(“”);
文件。填写(“”);
文件。填写(“”);
文件。填写(“”);
我在加载xml时没有问题,因为我已经测试过了,并且在我希望编写xml的部分中运行了一个脚本,它在该区域中编写得很好。我还使用一个普通div进行了测试,它工作得很好,只是在为该div分配类时似乎出现了问题

我已经运行了这段代码,看看document.write()编写div标记是否有问题,它工作正常,但没有任何格式

document.write("<div>");
document.write(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);
document.write("</div>");
document.write(“”);
document.write(x[i].getElementsByTagName(“标题”)[0].childNodes[0].nodeValue);
文件。填写(“”);
我只需要在main部分中编写一个div,然后将所有内容写入其中,但我需要为xml中的每个条目创建一个div,这是我唯一可以想到的方法

这是我需要为每个产品提供的div的基本概要

<div class="new_prod_box">
    <a href="details.html">product name</a>
    <div class="new_prod_bg"
    <a href="details.html"><img src="images/thumb1.gif" alt="" title="" class="thumb" border="0" /></a>
    </div>           
</div>


您在代码中弄乱了
。例如,第一行
文档。写(“”;

替换为
document.write(“”;

在HTML中还有div start

请尝试以下操作:

document.write('<div class="new_prod_box">\
  <a href="details.html">' + x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue + '</a>\
  <div class="new_prod_bg">\
      <a href="details.html"><img src="images/thumb1.gif" alt="" title="" class="thumb" border="0" /></a>\
  </div>\
</div>');
document.write('\
\
\
\
\
');

尝试使用单引号,只写一次:

var myhtml = "<div class='new_prod_box'>";
myhtml += "<a href='details.html'>");
myhtml += x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue;
myhtml += "</a>";
myhtml += "<div class='new_prod_bg'>";
myhtml += "<a href='details.html'><img src='images/thumb1.gif' alt='' title='' class='thumb' border='0' /></a>";
myhtml += "</div>";
myhtml += "</div>";
document.write(myhtml);
var myhtml=”“;
myhtml+=“”;
myhtml+=“”;
myhtml+=“”;
myhtml+=“”;
myhtml+=“”;
document.write(myhtml);

这是因为您的字符串包含双引号。您需要使用单引号或转义双引号。这是无效的:

document.write("<div class="new_prod_box">");
document.write(“”);
这些是:

document.write('<div class="new_prod_box">');
document.write("<div class=\"new_prod_box\">");
document.write(“”);
文件。填写(“”);