0
<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相当陌生,所以我不确定我做错了什么。:(如果需要任何其他细节,我很乐意提供。

4

1 回答 1

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);
}
于 2013-03-26T07:06:38.670 回答