gpt4 book ai didi

javascript - 代码无法在顶部使用 <!DOCTYPE html>

转载 作者:行者123 更新时间:2023-11-28 19:33:49 24 4
gpt4 key购买 nike

我有<!DOCTYPE html>在我的页面顶部,该页面应该做的是允许用户单击页面上的任意位置,然后重定向到另一个 URL。

当我删除 <!DOCTYPE html 时它就起作用了但我想将其保留在页面中

这是代码:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

<style>
BODY.enterPage{
cursor:hand;
}
</style>
<script>
function goto(){
location.href = "http://www.google.com"
}
</script>
</head>

<body class="enterPage" onclick="goto();">

Your Content

</body>

</html>

为什么会发生这种情况?

最佳答案

感谢@Pointy 评论,此外,请在 CSS 中进行以下更改:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
body.enterPage {
cursor: pointer; //Not hand!
}
html, body { //Set document width/height to 100%
width: 100%;
height: 100%;
}
</style>
<script>
function goto() {
location.href = "http://www.google.com"
}
</script>
</head>
<body class="enterPage" onclick="goto();">
Your Content
</body>
</html>

关于javascript - 代码无法在顶部使用 &lt;!DOCTYPE html>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26270750/

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