如何使用HTML中的JavaScript创建文本文件

时间:2014-04-08 02:30:02

标签: javascript html

我是一名真正的初学者。我想创建一个人们可以进入并选择我们正在做的游戏角色的网站。然后我想提示他们的全名,以便我可以在该按钮的文件夹中创建一个文件,这个文件名在他们的名下。在同一个提示中,我想输入它" / WINNER /"并让我从该按钮的文件夹中返回一个随机名称(文件名)。我希望这可以创造一个场景,而且我知道我可能正在做这个过于复杂的赌注,这是我发现这样做的唯一方式。也很抱歉,如果我的代码看起来有点不稳定,就像我说我是一个完整的菜鸟。

我的index.html

<head>
    <title>Check Please | Enter</title>
    <link href="css/styles.css" rel="stylesheet" type="text/css" media="screen">
    <link href='http://fonts.googleapis.com/css?family=Gafata|Metrophobic' rel='stylesheet' type='text/css' media="all">
</head>

<body>

    <div id="Welcome">
        <div id="WelcomeMessage">
            <h5 class="redCenter">Welcome to the voting website of</h5>
            <h3 class="Musical">'Check Please the Musical'</h3>
        </div>      

        <div id="Enter-Img">
            <a href="choice.html">
                <img src="images/site/enter.png" width="438" height="241" class="button">
            </a>
        </div>      
    </div>   

</body>

然后我的choice.html

<head>
    <title>Check Please | Voting</title>
    <link href="css/styles.css" rel="stylesheet" type="text/css" media="screen">
    <link href='http://fonts.googleapis.com/css?family=Gafata|Metrophobic' rel='stylesheet' type='text/css' media="all">
</head>

<body>

    <div id="Top">
        <h3 class="Musical">Please click on one of the following characters that you believe to be the murderer, and then enter your full name.</h3>
    </div>

        <div id="Button 1">
            <a href="Button 1/Button1.html">
                <img src="images/site/Person 1.png" width="438" height="241" class="enter">
            </a>
        </div>

        <div id="Button 2">
            <a href="Button 2/Button2.html" onclick="Name = prompt('Enter your first and last name')">
                <img src="images/site/Person 2.png" width="438" height="241" class="enter">
            </a>
        </div>

        <div id="Button 3">
            <a href="Button 3/Button3.html" onclick="Name = prompt('Enter your first and last name')">
                <img src="images/site/Person 3.png" width="438" height="241" class="enter">
            </a>
        </div>

        <div id="Button 4">
            <a href="Button 4/Button4.html" onclick="Name = prompt('Enter your first and last name')">
                <img src="images/site/Person 4.png" width="438" height="241" class="enter">
            </a>
        </div>

</body>

现在我只试着用一个按钮(Button1.html)搞砸了:

<head>
    <title>Check Please | Thanks and Enjoy</title>
    <link href="../css/styles.css" rel="stylesheet" type="text/css" media="screen">
    <link href='http://fonts.googleapis.com/css?family=Gafata|Metrophobic' rel='stylesheet' type='text/css' media="all">
</head>

<body>

    <script type="text/javascript">
        window.onload(Name = prompt("Enter your first and last name below"))

        import java.io.PrintWriter;

        if(Name == "/WINNER/") {
            window.location.replace("http://stackoverflow.com");

        }else{

            import java.io.PrintWriter;

            PrintWriter writer = new PrintWriter(Name + ".txt", "UTF-8");
            writer.close();
        };
    </script>

    <div>
        <h3 class="Musical">Button 1</h3>
    </div>

    <div>
    </div>


</body>

感谢您输入任何内容!!!!!!!

1 个答案:

答案 0 :(得分:3)

您似乎在JavaScript上下文中编写Java。我要说清楚一件事:JavaScript与Java无关。它们是完全独立的语言,因此您无法使用Java库。

此外,您无法使用JavaScript写出任何目录。 JavaScript在用户的浏览器中运行,该浏览器与服务器分开(您无法访问服务器上目录中的文件)