<html>
<head>
<title>Practice</title>
<script LANGUAGE="Javascript" type="text/javascript">
function myfunction() {
var element=document.getElementById("data1");
var element2=document.getElementById("bulkcontent");
var fname=prompt("Please enter your name:", "Your name");
var gend=prompt("Please enter your gender:", "Your gender");
var age=prompt("Please enter your age:", "Your age");
var pic=prompt("Please provide a picture url:", "Picture Url");
var r=confirm("Do you really wish to create a table? If you are unsatisfied with your result, please refresh the page.");
if(r==true)
{
element.innerHTML = "<table height='500' width='450' border='3' style='color:green;'><tr><th rowspan='3' height='350' width='250'><img src='" + pic + "' height='350' width='250' alt='UserPic' /></th><td height='150' width='200'><center><u>Name:</u></center><center>" + fname + "</center></td></tr><tr><td height='150' width='200'><center><u>Gender:</u></center><center>" + gend + "</center></td></tr><tr><td height='150' width='200'><center><u>Age:</u></center><center>" + age + "</center></td></tr><tr><td colspan='2'width='450' height='150'><center><u>Inventory</u></center><br/><center>1. --- 2. --- 3. --- 4. ---</center><br/></td></tr></table>";
element2.innerHTML = "<table border='3' style='color:green;'<tr><td colspan='2' height='400' width='400'><img src='http://i.imgur.com/b4lrB.jpg' alt='startarea' /></td></tr><tr><td width='60'><input type='button' value='enter' onClick='myfunction2()'></input><input type='button' value='Look Around' onClick='lookaround1()'></input></td><td width='340'><p>You are " + fname + ", and you have stumbled across this abandoned school house on a rainy night. You really don't want to go inside, but it's been miles and a " + gend + ", such as yourself, can't stand to be in the rain. What will you do?</p></td></tr></table>";
}
else if(r==false)
{
alert("Reconsider for a bit and return to us with a more decisive plan of action little wriggler.")
}
}
function myfunction2()
{
alert("Welcome Aka, please click the create table button to get started, but first read the paragraph in the table below! KK: DO IT FAST AKA HURRY THE F--K UP! THIS TIME IT IS DIFFERENT. YOU MIGHT ACTUALLY SEE A SLIDE COME UP!")
}
function lookaround1()
{
var audio=document.getElementById("audio");
setTimeout(lookaround1()
{audio.play();},3000);}
</script>
</head>
<body style="background-color:black;color:white;" onLoad="myfunction2()">
<div id="data1" style="opacity:0.5;width:0px;float:left;position:relative;left:0px;top:25px;">
</div>
<div id="bulkcontent" style="opacity:0.5;width:450px;height:550px;color:white;float:middle;position:relative;right:-460px;top:0px;">
<br/>
<hr/>
<br/>
<p>Welcome to the character creation menu, Today we are going to create a character. When you click on the create table button answer the promp questions as they are asked. Afterwards your character table shall be made. Scroll down a bit for the create table button!</p>
<br/>
<hr/>
<br/>
<center>Coded by Brandyn Porter. hOnK hOnK :o) 2013 </center>
</div>
<div id="links" style="opacity:0.7;width:250px;float:right;position:relative;right:85px;top:-475px;">
<img src="http://media.tumblr.com/tumblr_ln04c8bSpu1qin2iv.png" height="300" width="250" alt="gamzee" />
<hr/>
<br/>
<p style="color:white;">This is Gamzee. Gamzee says motherf--king hello, he also motherf--king asks for some motherfucking faygo. Are you gonna motherfucking deny this motherf--ker some motherf--king faygo? Yeah I didn't motherf--king think so.</p>
<br/>
<hr/>
</div>
<br/>
<hr width="1300" />
<br/>
<input onClick="myfunction()" style="float:middle;position:relative;right:-635px;top:25px;" type="button" value="Create Table" ></input>
<audio src="sc1.ogg" height="0" width="0" id="audio"></audio>
</body>
</html>
此代码适用于为网页选择自己的冒险故事类型的游戏。基本上这个页面做了一个非常原始的尝试来介绍,并且在创建创建表按钮时,会提示您几个问题,并将您的答案放入表格中。现在,您将看到三个表格,一个表格包含您在字符数据表中提供的信息,另一个表格包含图片和一些按钮和对话框,最后一个表格只是暂时装饰。现在我有一个输入按钮的占位符功能,但实际上我有一个“环顾四周”功能的预期功能。当按下它时,用户将在3秒后体验播放的声音,然后我打算给他们一个警告信息,告诉他们声音。我试图编写setTimeout函数,但每次我输入一些代码时,我的整个脚本都会中断,而且没有任何工作了。我对javascript很新,所以我不确定我做错了什么。 :(如果需要任何其他细节,我将很乐意提供。
答案 0 :(得分:0)
<html>
<head>
<title>Practice</title>
<script type="text/javascript">
function myfunction() {
var element = document.getElementById("data1");
var element2 = document.getElementById("bulkcontent");
var fname = prompt("Please enter your name:", "Your name");
var gend = prompt("Please enter your gender:", "Your gender");
var age = prompt("Please enter your age:", "Your age");
var pic = prompt("Please provide a picture url:", "Picture Url");
var r = confirm("Do you really wish to create a table? If you are unsatisfied with your result, please refresh the page.");
if (r == true) {
element.innerHTML = "<table height='500' width='450' border='3' style='color:green;'><tr><th rowspan='3' height='350' width='250'><img src='" + pic + "' height='350' width='250' alt='UserPic' /></th><td height='150' width='200'><center><u>Name:</u></center><center>"
+ fname
+ "</center></td></tr><tr><td height='150' width='200'><center><u>Gender:</u></center><center>"
+ gend
+ "</center></td></tr><tr><td height='150' width='200'><center><u>Age:</u></center><center>"
+ age
+ "</center></td></tr><tr><td colspan='2'width='450' height='150'><center><u>Inventory</u></center><br/><center>1. --- 2. --- 3. --- 4. ---</center><br/></td></tr></table>";
element2.innerHTML = "<table border='3' style='color:green;'<tr><td colspan='2' height='400' width='400'><img src='http://i.imgur.com/b4lrB.jpg' alt='startarea' /></td></tr><tr><td width='60'><input type='button' value='enter' onClick='myfunction2()'></input><input type='button' value='Look Around' onClick='lookaround1()'></input></td><td width='340'><p>You are "
+ fname
+ ", and you have stumbled across this abandoned school house on a rainy night. You really don't want to go inside, but it's been miles and a "
+ gend
+ ", such as yourself, can't stand to be in the rain. What will you do?</p></td></tr></table>";
} else if (r == false) {
alert("Reconsider for a bit and return to us with a more decisive plan of action little wriggler.")
}
}
function myfunction2() {
alert("Welcome Aka, please click the create table button to get started, but first read the paragraph in the table below! KK: DO IT FAST AKA HURRY THE F--K UP! THIS TIME IT IS DIFFERENT. YOU MIGHT ACTUALLY SEE A SLIDE COME UP!")
}
function lookaround1() {
var audio = document.getElementById("audio");
audio.play();
setTimeout(lookaround1, 3000);
}
</script>
</head>
<body style="background-color: black; color: white;"
onLoad="myfunction2()">
<div id="data1"
style="opacity: 0.5; width: 0px; float: left; position: relative; left: 0px; top: 25px;">
</div>
<div id="bulkcontent"
style="opacity: 0.5; width: 450px; height: 550px; color: white; float: middle; position: relative; right: -460px; top: 0px;">
<br />
<hr />
<br />
<p>Welcome to the character creation menu, Today we are going to
create a character. When you click on the create table button answer
the promp questions as they are asked. Afterwards your character
table shall be made. Scroll down a bit for the create table button!</p>
<br />
<hr />
<br />
<center>Coded by Brandyn Porter. hOnK hOnK :o) 2013</center>
</div>
<div id="links"
style="opacity: 0.7; width: 250px; float: right; position: relative; right: 85px; top: -475px;">
<img src="http://media.tumblr.com/tumblr_ln04c8bSpu1qin2iv.png"
height="300" width="250" alt="gamzee" />
<hr />
<br />
<p style="color: white;">This is Gamzee. Gamzee says motherf--king
hello, he also motherf--king asks for some motherf--king faygo. Are
you gonna motherf--king deny this motherf--ker some motherf--king
faygo? Yeah I didn't motherf--king think so.</p>
<br />
<hr />
</div>
<br />
<hr width="1300" />
<br />
<input onClick="myfunction()"
style="float: middle; position: relative; right: -635px; top: 25px;"
type="button" value="Create Table"></input>
<audio src="sc1.ogg" height="0" width="0" id="audio"></audio>
</body>
</html>
我猜你正在错误地使用setTimeout函数。
https://developer.mozilla.org/en/docs/DOM/window.setTimeout
function lookaround1() {
var audio = document.getElementById("audio");
audio.play();
setTimeout(lookaround1, 3000);
}