最基本的 e4x 测试的问题

发布于 2024-08-04 03:52:06 字数 946 浏览 5 评论 0原文

当我在 FF 3.5 中加载包含 e4x 的页面时,我没有意识到 e4x 甚至存在于浏览器的 JS 实现中。下面的注释,但这是我的 HTML:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>e4x test</title>
    <script type="text/javascript" src="lib/dojo/dojo/dojo.js">
    </script>
    <script type="text/javascript;e4x=1">
        function hello() {
            var x = new XML();
            x = <foo></foo>
            dojo.byId("container").innerHTML = "Print me!" + x.toXMLString();
        }
    </script>
    <script type="text/javascript">
        dojo.addOnLoad(hello);
    </script>
</head>
<body>
<div id="container">
</div>
</body>
</html>

当我在 firebug 中检查时,它说 x 没有 toString() 方法,并且我的 IDE (aptana) 认为 XML 不是对象类型。有谁知道我做错了什么?

When I load a page containing e4x in FF 3.5, I get no inkling that e4x even exists in the browser's JS implementation. Notes below, but here's my HTML :

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>e4x test</title>
    <script type="text/javascript" src="lib/dojo/dojo/dojo.js">
    </script>
    <script type="text/javascript;e4x=1">
        function hello() {
            var x = new XML();
            x = <foo></foo>
            dojo.byId("container").innerHTML = "Print me!" + x.toXMLString();
        }
    </script>
    <script type="text/javascript">
        dojo.addOnLoad(hello);
    </script>
</head>
<body>
<div id="container">
</div>
</body>
</html>

When I inspect in firebug, it says x doesn't have a toString() method, and my IDE (aptana) thinks that XML is not an object type. Does anyone have any idea what I'm doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

这个俗人 2024-08-11 03:52:06

我猜它一直在工作,但是您的浏览器无法识别“foo”标签,并且因为它不知道如何呈现它,所以它会忽略它。通过在 foo 标签中放入一些内容,您将获得内容。

顺便说一句:new XML() 语句是完全没有必要的。您可以这样做:

var x = <foo>bar</foo>;

这将为您创建一个新的 XML 对象。说 new XML() 就像说 new String() 一样。你可以做到,但这只是浪费空间。

I'm guessing that it was working all along, but your browser doesn't recognize a "foo" tag and because it does not know how to render it, it ignores it. By putting something inside of your foo tag you would get content out.

BTW: The new XML() statement is entirely unnecessary. You can just do this:

var x = <foo>bar</foo>;

That will create a new XML object for you. Saying new XML() is like saying new String(). You can do it, but it is just a waste of space.

错々过的事 2024-08-11 03:52:06

事实证明,我需要 XML 中的更多内容才能打印出任何内容。例如,酒吧工作。我不知道为什么,但这就是解决它的原因!

It turns out that I need more in the XML for it to print anything out. bar works, for example. I'm not sure why, but that is what fixed it!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文