HTML中.HTA应用程序使用JavaScript被修改后不更新 [英] HTML does not update after being modified with JavaScript in .hta application

查看:91
本文介绍了HTML中.HTA应用程序使用JavaScript被修改后不更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含JavaScript和HTML中.HTA文件。我的JavaScript code修改与喜欢的appendChild功能的HTML,但是HTML没有得到事后更新;即使元件在DOM-结构corretly所附(Ⅰ可以提醒.innerHTML,返回HTML- code象它应该是,但它并不在浏览器中显示)。如果放在一个HTML文件,它的工作原理完全没问题。

 <!DOCTYPE HTML>
< HTML和GT;
< HEAD>
  < HTA:应用程序ID =prjreq_v1的applicationName =ProjectRequirements>
    <脚本>
    功能appendDiv(){        //获取将获得附加元素
        变种ContentElement的=的document.getElementById(main_table);        //创建表行
        VAR TR =使用document.createElement(TR);
        tr.id = 0;        //创建表列
        VAR td_0 =使用document.createElement(TD);
        td_0.id =日期;
        td_0.innerText =22/22/2222;        //附加
        tr.appendChild(td_0);
        contentElement.appendChild(TR);        //警报输出修正HTML,但是它并不显示...
        警报(contentElement.innerHTML);
    }
    < / SCRIPT>
< /头>
<身体GT;
    < D​​IV ID =内容>
        <表ID =main_table>
            &所述; TR>
                百分位ID =日期>日期和LT; /第i
                百分位ID =源>来源< /第i
                百分位ID =规定>说明与LT; /第i
            < / TR>
            &所述; TR的id =100>
                < TD ID =日期> DD / MM / YYYY< / TD>
                < TD ID =源>例1源和LT; / TD>
                < TD ID =规定> Lorem存有多洛雷斯EST< / TD>
            < / TR>
        < /表>
    < / DIV>
    <脚本>(函数(){appendDiv();})();< / SCRIPT>
< /身体GT;
< / HTML>


解决方案

Internet Explorer已经一向真的挑剔添加行的表。所有的浏览器,但是,假设你的表行包含在< TBODY> 元素,它是有效的桌子,有多个< TBODY> 元素。 (你无法看到它们在屏幕上;它只是一个结构性的东西)

因此​​,如果你换你的< TR> < TBODY> 然后追加的应用于<表> ,它应该工作

(我没有IE浏览器一应俱全,但它的可能的工作,如果你要明确包括< TBODY> 要不然发现隐含的,然后瞄准,与 .appendChild()电话。)

I have a .hta File containing JavaScript and HTML. My JavaScript Code modifies the HTML with functions like "appendChild", but the HTML does not get updated afterwards; Even if the element was corretly appended in the DOM-Structure (I can alert the .innerHTML, returning the html-code like it should be, but it doesn't show in the browser). If put in an HTML-File, it works completely fine.

<!DOCTYPE html>
<html>
<head>
  <hta:application id="prjreq_v1" applicationname="ProjectRequirements">
    <script>
    function appendDiv(){

        //Get the element that will get appended
        var contentElement = document.getElementById("main_table");

        //Create table row
        var tr = document.createElement("tr");
        tr.id = 0;

        //Create table column
        var td_0 = document.createElement("td");
        td_0.id = "date";
        td_0.innerText = "22/22/2222";

        //Append
        tr.appendChild(td_0);
        contentElement.appendChild(tr);

        //Alert outputs the modified HTML, but it doesn't show...
        alert(contentElement.innerHTML);
    }
    </script>
</head>
<body>
    <div id="content">
        <table id="main_table">
            <tr>
                <th id="date">Date</th>
                <th id="source">Source</th>
                <th id="requirement">Description</th>
            </tr>
            <tr id="100">
                <td id="date">dd/MM/yyyy</td>
                <td id="source">Example1 Source</td>
                <td id="requirement">Lorem Ipsum dolores est</td>
            </tr>
        </table>
    </div>
    <script>(function (){appendDiv();})();</script>
</body>
</html>

解决方案

Internet Explorer has always been really picky about adding rows to tables. All browsers, however, assume that your table rows are contained in a <tbody> element, and it's valid for a table to have multiple <tbody> elements. (You can't see them on the screen; it's just a structural thing.)

Thus if you wrap your <tr> in a <tbody> and then append that to the <table>, it should work.

(I don't have IE readily available, but it might work if you were to explicitly include the <tbody> or else find the implicitly included one, and then target that with the .appendChild() call.)

这篇关于HTML中.HTA应用程序使用JavaScript被修改后不更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆