最基本的 e4x 测试的问题
当我在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜它一直在工作,但是您的浏览器无法识别“foo”标签,并且因为它不知道如何呈现它,所以它会忽略它。通过在 foo 标签中放入一些内容,您将获得内容。
顺便说一句:new XML() 语句是完全没有必要的。您可以这样做:
这将为您创建一个新的 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:
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.
事实证明,我需要 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!