0

我无法让 Javascript 在网站上列出“开始”数字,因为它是空的。

这是我的html正文代码,

<script type="text/javascript">
    captionsDoc = loadXMLDoc("captions.xml");
    x=captionsDoc.getElementsByTagName('text');

    for(i=0;i<x.length;i++)
    {
        document.write(x[i].getAttribute('start'));
        document.write("/n");

    }
</script>

那么这是来自 captions.xml 的 xml 代码示例

<transcript>
<text start="6.738" dur="2.277">and explain a few interesting points about them.</text>
<text start="9.016" dur="2.722">But first I need to crush your expectations.</text>
<text start="24.716" dur="1.611">So let&#39;s begin.</text>
<text start="26.328" dur="2.535">First we start with the solvent diethyl phthalate.</text></transcript>
4

1 回答 1

1

你有

document.wite("
")

你应该有

document.write("\n");

然后它在这里具有魅力,加载功能来自:http ://www.w3schools.com/dom/dom_loadxmldoc.asp

像这样:

<html>
    <head>
        <title>HTML5 included Javascript....</title>
        <meta name="description" content="Test" charset="utf-8"></meta>
        <script type="text/javascript">
            function loadXMLDoc(dname)
            {
                if (window.XMLHttpRequest)
                {
                xhttp=new XMLHttpRequest();
                }
                else
                {
                xhttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                xhttp.open("GET",dname,false);
                xhttp.send();

                return xhttp.responseXML;
            }

            function init()
            {
                var c = document.getElementById('container');
                captionsDoc = loadXMLDoc("captions.xml");
                x=captionsDoc.getElementsByTagName('text');

                for(i=0;i<x.length;i++)
                {
                    c.innerHTML += x[i].getAttribute('start');
                    c.innerHTML += "\n";
                }
            }

            window.onload = init;
        </script>
    </head>

    <body>
        <div id="container">
        </div>
    </body>
</html> 
于 2013-03-13T19:23:27.727 回答