2014-04-08 67 views
0

我是一个真正的初学者,我想创建一个网站,人们可以去选择一个我们正在做的戏剧的角色。然后我会提示输入他们的全名,这样我就可以在该文件夹中为该按钮创建一个文件,这就是他们的名字。在同样的提示中,我想输入“/ WINNER /”,然后让我从该按钮的文件夹中找回一个随机名称(文件名)。我希望这种情景能够成为现实,而且我知道我可能会让这个过于复杂的赌注成为我发现的唯一办法。如果我的代码看起来有点won Also,也很抱歉,就像我说我是一个完整的noob。如何用HTML创建一个带有JavaScript的文本文件

我的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> 

谢谢为任何输入!!!!!!!

+0

我认为JavaScript在浏览器中没有创建文件的库或函数。你的意思是nodejs? –

+0

请参阅http://stackoverflow.com/questions/1087246/can-javascript-access-a-filesystem –

+0

为什么你有'java'标签? –

回答

3

您似乎是在JavaScript上下文中编写Java。我会做一件事情非常清楚:JavaScript与Java无关。它们是完全独立的语言,因此您不能使用Java库。

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

+0

哦好吧谢谢我会做更多的研究。 – user3509162

相关问题