Javascript不会加载html密码提示

时间:2016-06-14 01:11:47

标签: javascript

这里我有一个网站,我尝试使用内部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>

2 个答案:

答案 0 :(得分:0)

onload事件 - &gt; 支持的HTML标记:

<body>, <frame>, <frameset>, <iframe>, <img>, <input type="image">, <link>, <script> and <style>

show this page

和..正确的语法是onload = "password_prompt()"

右??

答案 1 :(得分:0)

  1. 添加结束html标记:</html>
  2. <body>标记中触发您的功能: <body onload="password_prompt();"></body>
  3. “javascript”中有拼写错误,应该是: <script type = "text/javascript">