-1

click_function_ps()一旦函数执行,我编写了代码来刷新 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>
4

3 回答 3

3

尝试这个

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

此外,没有具有 ID 的元素scrollbar。将 DIV 从 更改class="scrollbar"id="scrollbar"或立即使用 IDchart或通过以下操作替换 javascript document.getElementsByClassName("scrollbar")[0]。但请记住,getElementsByClassName()IE 不支持。我强烈建议使用id而不是class.

于 2012-05-25T09:14:13.030 回答
1

在这部分你没有逃避双引号:

function replaceContent() {
   var newHTML = "<img class=\"displayed\" src=\"ganttchart.php\">";
   document.getElementById("scrollbar").innerHTML = newHTML;
}
于 2012-05-25T09:15:14.620 回答
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在您编写代码时检查您的语法错误..

于 2012-05-25T09:18:46.740 回答