这里我有一个网站,我尝试使用内部javascript加载提示,除非输入正确的密码,否则页面将无法加载。以下是代码的相关部分。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head onload = password_prompt()>
<script type = "text/javscript">
function password_prompt() {
var password = window.prompt("Please enter the correct password ", ""); //password = javascript
if (password == "javascript") {
}
if ((password !== "123") && (password !== "")) {
window.alert("You entered the wrong password! Page will now close!");
}
}
</script>
<title>My JavaScript Site - Home</title>
<link rel="stylesheet" type="text/css" media="all" href="layout.css" />
</head>
答案 0 :(得分:0)
onload事件 - &gt; 支持的HTML标记:
<body>, <frame>, <frameset>, <iframe>, <img>, <input type="image">, <link>, <script> and <style>
和..正确的语法是onload = "password_prompt()"
?
右??
答案 1 :(得分:0)
</html>
<body>
标记中触发您的功能:
<body onload="password_prompt();"></body>
<script type = "text/javascript">