2013-03-12 85 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