2012-05-25 73 views
-1

一旦執行函數click_function_ps(),我編寫了刷新DIV容器的代碼。但我的代碼不起作用。它說:刷新DIV容器

missing ; before statement 
var newHTML = "<img class="displayed" src="ganttchart.php">"; 

那麼,我需要在哪裏把;

<div class="buttons"> 
    <a href="#" class="regular" onclick="click_function_ps(); replaceContent();"> 
     <img src="images/opt.png" alt=""/> Run </a> 
</div> 

<div id="opt_container"> 
     <table width="100%"> 
      <tr> 
       <td width="100%"> 
        <div class="scrollbar" id="chart"> 
         <img class="displayed" src="ganttchart.php"> 
        </div> 
       </td> 
      </tr> 
     </table> 
</div> 


<script type="text/javascript"> 
function replaceContent() { 
    var newHTML = "<img class="displayed" src="ganttchart.php">"; 
    document.getElementById("scrollbar").innerHTML = newHTML; 
} 
</script> 
+0

var newHTML =''; – Ruben

回答

3

嘗試此

var newHTML = "<img class=\"displayed\" src=\"ganttchart.php\">"; 

此外,不存在與ID scrollbar沒有元素。將DIV從class="scrollbar"更改爲id="scrollbar"或立即使用ID chart,或者按照document.getElementsByClassName("scrollbar")[0]替換javascript。但請記住,IE不支持getElementsByClassName()。我強烈推薦使用id而不是class

+0

好吧,但現在它說:document.getElementById(「滾動條」)爲空,當我按「運行」 –

+0

我已更新我的答案。請重新檢查。 – Amberlamps

+0

是的,現在沒有錯誤(我用getElementById(「圖表」)),但按下運行後DIV的內容變空。我需要按Ctrl + R來查看新圖表。所以,似乎還剩下一些其他東西。 –

1

您沒有逃脫雙引號中的這一部分:

function replaceContent() { 
    var newHTML = "<img class=\"displayed\" src=\"ganttchart.php\">"; 
    document.getElementById("scrollbar").innerHTML = newHTML; 
} 
0

您可以嘗試以下: -

<div class="buttons"> 
    <a href="#" class="regular" id="scrollbar" onclick="click_function_ps(); replaceContent();"> 
     <img src="images/opt.png" alt=""/> Run </a> 
</div> 

<div id="opt_container"> 
     <table width="100%"> 
      <tr> 
       <td width="100%"> 
        <div class="scrollbar" id="chart"> 
         <img class="displayed" src="ganttchart.php"> 
        </div> 
       </td> 
      </tr> 
     </table> 
</div> 


<script type="text/javascript"> 
function replaceContent() { 
    var newHTML = "<img class=\"displayed\" src=\"ganttchart.php\">"; 
    document.getElementById("scrollbar").innerHTML = newHTML; 
} 
</script> 

這種類型的錯誤不會來,如果你會使用任何IDE(netbeans etc)。 因爲IDE檢查你的語法錯誤,而你正在做的代碼..

+0

問題是,現在它說:document.getElementById(「scrollbar」)爲空,當我按「運行」 –

+0

在您的問題編輯。 ..提到這個問題 –

+0

你在哪裏定義你的樂趣click_function_ps(); –