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>

このコードは、Web ページ用に独自のアドベンチャー ストーリー タイプのゲームを作成するためのものです。基本的に、このページは非常に原始的な紹介を試みます。テーブル作成ボタンを作成すると、いくつかの質問が表示され、回答がテーブルに表示されます。その後、3 つのテーブルが表示されます。1 つは文字データ テーブル内に提供した情報、もう 1 つは画像といくつかのボタンとダイアログを含むテーブル、そして最後のテーブルは当面の装飾です。これで、Enter ボタンのプレースホルダー関数ができましたが、実際には「Look Around」関数の意図した関数があります。ボタンを押すと、ユーザーは 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 に答える