gpt4 book ai didi

javascript - Firefox 是否支持 XHTML 页面中的 Javascript?

转载 作者:数据小太阳 更新时间:2023-10-29 02:49:30 25 4
gpt4 key购买 nike

我需要提供包含 Javascript 的 XHTML 页面。我的问题是 Firefox (3.5.7) 似乎忽略了 Javascript。例如:

<?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My Title</title>
</head>
<body>
<script type="text/javascript">
document.write("Hello world!");
</script>
</body>
</html>

如果我将它保存为 test.html,Firefox 会正确显示它。如果我将其保存为 test.xml,Firefox 会显示一个空白页面。我在这里做错了什么?

最佳答案

来自 http://www.w3.org/MarkUp/2004/xhtml-faq#docwrite

Does document.write work in XHTML?

No. Because of the way XML is defined, it is not possible to do tricks like this, where markup is generated by scripting while the parser is still parsing the markup.

You can still achieve the same effects, but you have to do it by using the DOM to add and delete elements.

关于javascript - Firefox 是否支持 XHTML 页面中的 Javascript?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2243837/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com