簡體   English   中英

window.open function 僅在 foreach 循環中運行一次

[英]window.open function only runs once in foreach loop

所以我有這個名為“文檔”的文本,當我左鍵單擊時帶有正常的href。 但是當我右鍵單擊它時,它會打開一個彈出窗口 window,它應該如此。 當我只有一個 id 時效果很好,但假設我選擇 10 [0 1 2 3 4 5 6 7 8 9],那么 9 將是唯一鏈接到一次的:EditText?testjobid=9。 該鏈接還附加到 id = 0 的“文檔”。我做錯了什么?

foreach ($AllTestResultsTestJob as $TestJob)
  {
    $testjobid    = $TestJob['TestjobId'];
    echo "<th style=''><center><a id='EditText' style='color:#000' class='links' href= 'Documentation?testjobid=".$testjobid."' target='_blank'>Documentation</th>"; 

  </center>
    </th>";
echo"
    <script>
    document.getElementById('EditText').onmousedown = function(event) {


      if (event.which == 3) {
        window.open('EditText?testjobid=".$testjobid."', 'myWindow', 'width=1000,height=390');
      }
    }
    </script>
    ";

您對多個元素使用相同的id='EditText' ,因此您應該更改您的 id 和 select 與另一個選擇器的鏈接。

因此,將您的鏈接更改為:

 echo "<th style=''><center><a id='EditText-".$testjobid."' style='color:#000' class='links' href= 'Documentation?testjobid=".$testjobid."' target='_blank'>Documentation</th>";

並將您的活動更改為:

echo"
    <script>
    document.getElementById('EditText-".$testjobid."').onmousedown = function(event) {


      if (event.which == 3) {
        window.open('EditText?testjobid=".$testjobid."', 'myWindow', 'width=1000,height=390');
      }
    }
    </script>
    ";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM