Php 刷新DIV容器

Php 刷新DIV容器,php,javascript,ajax,Php,Javascript,Ajax,我编写了代码,以在函数单击\u function\u ps()执行后刷新DIV容器。但是我的代码不起作用。它说: missing ; before statement var newHTML = "<img class="displayed" src="ganttchart.php">"; 试试这个 var newHTML = "<img class=\"displayed\" src=\"ganttchart.php\">"; var newHTML=”“; 此外

我编写了代码,以在函数
单击\u function\u ps()
执行后刷新DIV容器。但是我的代码不起作用。它说:

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

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

此外,没有ID为滚动条的元素。将DIV从
class=“scrollbar”
更改为
id=“scrollbar”
,或者立即使用id
chart
,或者按照
document.getElementsByClassName(“scrollbar”)[0]
替换javascript。但请记住,IE不支持
GetElementsByCassName()
。我强烈建议使用
id
而不是
class

在这一部分中,您没有逃脱双引号:

function replaceContent() {
   var newHTML = "<img class=\"displayed\" src=\"ganttchart.php\">";
   document.getElementById("scrollbar").innerHTML = newHTML;
}
函数replaceContent(){
var newHTML=“”;
document.getElementById(“滚动条”).innerHTML=newHTML;
}
您可以尝试以下方法:-

<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>

函数replaceContent(){
var newHTML=“”;
document.getElementById(“滚动条”).innerHTML=newHTML;
}
如果使用任何
IDE(netbeans等)
,则不会出现此类错误。。
因为
IDE
在编写代码时检查语法错误。

var newHTML='';好的,但现在它说:document.getElementById(“滚动条”)为空,当我按“Run”时是的,现在没有错误(我使用了getElementById(“chart”)),但按Run后DIV的内容变为空。我需要按Ctrl+R键才能看到新图表。因此,似乎还剩下一些东西问题是现在它说:document.getElementById(“scrollbar”)是空的,当我按“Run”时,你定义了你的有趣的点击函数;
<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>