2013-03-12 90 views
1

我是新的使用跨度。我试图打印出我从同一页面上的两次JavaScript脚本获取的信息。<span> html重复打印出来

我可以打印,我得到一次,但是当我确定要打印的信息第二次它不显示它

这一个工程

<div id="layer4" class="auto-style10" style="position: absolute; width: 300px; height: 427px; z-index: 2; left: 1020px; top: 90px"> 
    <span class="auto-style8"><h4>Incident Details</h4><br /> 
     </span> 
    <br /> 

&nbsp;<h6> Report ID : </h6> &nbsp; <span id="ReportID"></span> <br /> 

&nbsp;<h6> Description : </h6> &nbsp; <span id="Description"></span><br /> 

&nbsp;<h6> Category : </h6> &nbsp; <span id="Category"></span> <br/> 

&nbsp;<h6> Date and Time : </h6> &nbsp; <span id="DateTime"></span> <br /> 

&nbsp;<h6> User Id/ Mobile Number : </h6> &nbsp; <span id="UserID"></span><br /> 
    <br /> 


<span id="ReportID"></span> 
    <form method="post" action="http://www.al-qarra.com/police_new/map2/changelevel.php" > 

<select name="SelectCat" style="position: absolute; width: 60px; z-index: 2;"> 
<option>1</option> 
<option>2</option> 
<option>3</option> 
</select> 
<input name="reportno" type="hidden" value="<?php echo $_SESSION['incidentid']; ?>"> 

<input name="ChangeCat" id="SelectCat" type="submit" value="Change Status" style="position: absolute; left: 100px; width: 110px; z-index: 2;"/> 

     </form> 

</div> 

但是,当我复制信息同一格到相同的页面但不同的位置它不显示信息

<div id="layer44" class="auto-style10" style="position: absolute; width: 300px; height: 427px; z-index: 2; left: 1020px; top: 300px"> 
    <span class="auto-style8"><h4>Incident Details</h4><br /> 
     </span> 
    <br /> 

&nbsp;<h6> Report ID : </h6> &nbsp; <span id="ReportID"></span> <br /> 

&nbsp;<h6> Description : </h6> &nbsp; <span id="Description"></span><br /> 

&nbsp;<h6> Category : </h6> &nbsp; <span id="Category"></span> <br/> 

&nbsp;<h6> Date and Time : </h6> &nbsp; <span id="DateTime"></span> <br /> 

&nbsp;<h6> User Id/ Mobile Number : </h6> &nbsp; <span id="UserID"></span><br /> 
    <br /> 

</div> 

这是我的javascript的要求

</style> 
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script> 

      $("#ReportID").text(nreportid); 
      $("#Description").text(ndesc); 
      $("#Category").text(ncat); 

    } 
    </script> 

回答

1

我到目前为止已经发现了几个问题:

  • 你有重复的ID,这是不允许的。
  • 认为您要添加您要添加​​这些元素在其他地方,但你将它们定位绝对,所以他们一定重叠
  • 你离开<span>元素空,但在标签之间添加&nbsp; ...看起来像是在制作标签汤
  • 第一个代码的末尾有一个表单,第二个没有。看到它们重叠时,他们第二批节点可能会永远藏起来。
  • 您的JavaScript代码包含两个(huuuge)函数,这些函数不被称为AFAIK。这可能会遇到粗鲁/傲慢,但请,整理您的代码建议in the FAQ
  • 你搞乱了z-index,为什么?

但是,只要您没有向我们展示您的JavaScript代码,这些猜测都不会变得非常确定。例如,如果您使用的是document.write('your-html');,那么我们可以告诉您这是您的问题,并且我们的方法将永远存在...因此请set up a decent fiddle or something

+0

我已更新我的问题,其中包括javascript – 2013-03-13 00:15:31

+0

@MuzZaden而我编辑了我的答案 – 2013-03-13 00:22:15

+0

所以你说我应该只是将每个元素的名称替换为别的东西,这将起作用 – 2013-03-13 00:32:07

0

尝试删除

style="position: absolute; width: 300px; height: 427px; z-index: 2; left: 1020px; top: 300px" 
+0

此解决方案没有工作:( – 2013-03-13 00:02:25

0

id属性是必须是唯一的。如果页面上有多个项目需要执行相同的操作,请改为使用class

+0

这两个id是不同的,一个是id =“layer4”和其他是id =“layer44” – 2013-03-13 00:05:39

+0

''等都是相同的。 – 2013-03-13 00:06:51

+0

id =“ReportID”是我从javascript获得的输出,所以我不能真的改变它 – 2013-03-13 00:08:39