HTA追加表格行

时间:2015-05-01 15:47:54

标签: html windows hta

我有以下代码用于Windows系统的HTA文件。但是,该表不会使用新行进行更新。有解决方法吗?相同的代码在Chrome浏览器中运行良好。

<!DOCTYPE html>
<HTML>
    <HEAD>
        <meta http-equiv="MSThemeCompatible" content="Yes"/>
        <TITLE>
            Protos Changer
        </TITLE>
        <HTA:APPLICATION
            ID = "oApp"
            APPLICATIONNAME = "Protos Changer"
            BORDER = "thick"
            CAPTION = "yes"
            ICON = "hw.ico"
            SHOWINTASKBAR = "yes"
            SINGLEINSTANCE = "no"
            WINDOWSTATE = "normal"
            SCROLL = "no"
            SCROLLFLAT = "yes"
            VERSION = "1.1"
            INNERBORDER = "no"
            SELECTION = "no"
            SYSMENU = "yes"
            MAXIMIZEBUTTON = "yes"
            MINIMIZEBUTTON = "yes"
            NAVIGABLE = "yes"
            CONTEXTMENU = "no"
            BORDERSTYLE = "thin"
        />
        <SCRIPT type="text/javascript">
            function init()
            {
                print_stuff('label 1', 'value 1')
                print_stuff('label 2', 'value 2')
                print_stuff('label 3', 'value 3')
                print_stuff('label 4', 'value 4')
                print_stuff('label 5', 'value 5')
                print_stuff('label 6', 'value 6')
            }
            function print_stuff(row_label, row_value)
            {
                var tbl_row = document.createElement('tr')
                var tbl_lbl = document.createElement('td')
                var tbl_val = document.createElement('td')
                var txt_lbl = document.createTextNode(row_label)
                var txt_val = document.createTextNode(row_value)
                tbl_lbl.appendChild(txt_lbl)
                tbl_val.appendChild(txt_val)
                tbl_row.appendChild(tbl_lbl)
                tbl_row.appendChild(tbl_val)
                document.getElementById('page_table').appendChild(tbl_row)
            }
        </SCRIPT>
        <STYLE TYPE="text/css">
        <!--
            body        {background:buttonface;color:buttontext;font:10pt Arial;overflow:hidden;}
            select      {}
            #page_table,td  {border:solid 2px #000;}
            td      {width:10em;height:2em;}
        -->
        </STYLE>
    </HEAD>
    <BODY onload="init()">
        <table id="page_table">
            <tr>
                <td>Label</td>
                <td>Value (old)</td>
            </tr>
        </table>
    </BODY>
</HTML>

1 个答案:

答案 0 :(得分:1)

我在这里找到了解决方案:

Can't dynamically add rows to a <TABLE> in IE?

解决方案是创建一个TBODY元素并将行追加到它而不是TABLE元素。