2012-08-26 34 views
0

我使用這個javascript/jquery來隱藏我的頁面的一部分,並顯示一個新的部分。它昨天正在工作,然後我今天來了,它不工作。我做了一些編輯,比如添加了一個「下雪」的javascript,以及一個javascript代碼,它通過點擊一個按鈕來改變bg顏色,但是我刪除了所有改變了的東西,但它仍然不起作用......這是我的整個代碼...Javascript顯示/隱藏隨機不工作

<html><head> 

    <script src="http://code.jquery.com/jquery-latest.js"></script> 
     <link href="http://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet" type="text/css" > 
<script type="text/javascript"> <!-- Hides something then shows something. --> 
function friedrice(id, id2) { 
    $('#' + id).hide(); 
    $('#' + id2).show(); 

} 
</script> 


<script type="text/javascript"> <!-- Show stuff with fade in --> 
    function showStuff(id) { 
     document.getElementById(id).style.display = 'block'; 
object = document.getElementById(id) 

$(object).hide(); 
     $(object).fadeIn(1000); 
    } 
</script> 




<script type="text/javascript"> <!-- Hides hidden stuff on load --> 

$(document).ready(function(){ 
    $('#swf').hide(); 
    $('#surprise').hide(); 
}); 

</script> 

<script type="text/javascript"> <!-- Shows stuff --> 
function katana(id) { 
    $('#' + id).show(); 

} 
</script> 


<script type="text/javascript"> <!-- Popup on exit --> 
function box() 
{ 
var r=confirm("Content") 
if (r==true) 
    { 
    window.location.href="russia.html"; 
    } 
else 
    { 
    window.location.href="china.html"; 
    } 
} 
</script> 


</head> 
    <body onunload="box()"; 
    <div id="chopsticks"> <!-- This is the "main" content that is displayed before the last checkbox is checked --> 
    <OBJECT id="swf" style="z-index:2; position:absolute; top:20%; left:15%;" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="90%" HEIGHT="70%" id="rice" ALIGN=""><PARAM NAME=movie VALUE="rice.swf"><PARAM NAME=quality VALUE=low><EMBED src="rice.swf" quality=low bgcolor=#EEEEEE WIDTH="90%" HEIGHT="90%" NAME="rice" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED> </OBJECT> 

<center><h1>Logo Here!</h1><br> 
</center> 
        <span id="a1" style="display: block;"><div class="texts" > 
            <div class="title" > 
        <strong>Step 1</strong><br><br> 
       </div> 

<div class="rice">Content<br></div> 
<label class="label_check" > 
    <input name="sample_check1" id="sample_check1" value="1" type="radio" onclick="showStuff('a2')" /> 
Done? 
    </label></div></span> 
<br> 
        <span id="a2" style="display: none;"><div class="texts"> 

            <div class="title" > 
        <strong>Step 2</strong><br><br> 
       </div> 

<div class="rice">Content<br></div> 
<label class="label_check" > 
    <input name="sample_check2" id="sample_check2" value="1" type="radio" onclick="showStuff('a3');" /> 
Done? 
    </label> 
       </div></span> 
<br> 
        <span id="a3" style="display: none;"><div class="texts"> 

            <div class="title" > 
        <strong>Step 3</strong><br><br> 
       </div> 
        <div class="rice">Content<br></div> 
<label class="label_check" > 
    <input name="sample_check3" id="sample_check3" value="1" type="radio" onclick="showStuff('stage');setTimeout(katana, 10000, 'swf');setTimeout(friedrice, 12000, 'chopsticks', 'surprise');" /> <!-- The showStuff function will show an image with a fade in. The katana function will show the swf, then 2 seconds later, the "friedrice" function will remove all of the the content on the page including the swf and show new "surprise" content. --> 
Ready? 
    </label> 
       </div></span> 

     <span id="stage" style="display:none;"> 
      <img src="images/dot.png" style=" position:absolute; left:44%; top:20%;"/> 
     </span> 


        <script> 
     $('body').hide(); 
     $('body').fadeIn(1000); 
    </script> 
</div> 
<div id="surprise"> <!-- This is the "hidden" content that is displayed 12 seconds after the checkbox is checked --> 
<center> 
<p> i jo</p> 
<embed src="scare.mp3" autoplay="true" loop="true" height="240" width="100" /></embed> 
</div> 
</center> 
</body></html> 

這是沒有的CSS,因爲我認爲這是沒有必要的。重要的部分被評論。請原諒sloppiness和變量名稱,函數等我通常不會給我的代碼xD。但我不知道發生了什麼,我改變了所有改變的事情。希望有人能幫忙。謝謝!

+1

你有沒有試過清除緩存?有時腳本會被緩存,並且在刷新緩存之前,它不會使用新代碼進行更新。這發生在我清理我的瀏覽器(Firefox)中的緩存之前和之後,它又開始工作了。 – Ishikawa

+0

@Ishikawa是的,我試過多個瀏覽器,清除緩存,甚至多臺電腦。當我改變東西的時候,那裏肯定會有一些縈繞不去的代碼。我真的不知道。 –

回答

2

有一個;後失蹤object = document.getElementById(id)

<script type="text/javascript"> <!-- Show stuff with fade in --> 
    function showStuff(id) { 
     document.getElementById(id).style.display = 'block'; 
     object = document.getElementById(id); 
           //this one^ 
     $(object).hide(); 
     $(object).fadeIn(1000); 
} 
</script> 

變種r=confirm("Content")也少了一種;在退出部分彈出

+0

是的,我剛剛也看到了。這絕對是破壞代碼。在添加分號後查看它是否有效。 – Ishikawa

+0

+1其始終是小東西。 –

+0

我修正了這個問題,沒有任何改變。清除緩存還:( –

0

嘗試將您的瀏覽器設置,並清除緩存,這可能幫助了。

+0

已經嘗試過:/ –

0

我已經改變了一些代碼,現在我沒有收到errormessage的:

<html> 
<head> 
<title>Page title</title> 
<link href="http://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet" type="text/css" > 

<script src="http://code.jquery.com/jquery-latest.js"></script> 

<script type="text/javascript"> <!-- Hides something then shows something. --> 
function friedrice(id, id2) { 
    $('#' + id).hide(); 
    $('#' + id2).show(); 
} 
</script> 

<script type="text/javascript"> <!-- Show stuff with fade in --> 
function showStuff(id) { 
    document.getElementById(id).style.display = 'block'; 
    object = document.getElementById(id) 

    $(object).hide(); 
     $(object).fadeIn(1000); 
    } 
</script> 

<script type="text/javascript"> <!-- Hides hidden stuff on load --> 
$(document).ready(function(){ 
    $('#swf').hide(); 
    $('#surprise').hide(); 
}); 
</script> 

<script type="text/javascript"> <!-- Shows stuff --> 
function katana(id) { 
    $('#' + id).show(); 
} 
</script> 

<script type="text/javascript"> 
function box(){ 
    var r = window.confirm("Content"); 
    if(r==true){ 
     window.location.href="russia.html"; 
    } 
    else{ 
     window.location.href="china.html"; 
    } 
} 
</script> 

</head> 
    <body onUnload="box"> 
    <div id="chopsticks"> <!-- This is the "main" content that is displayed before the last checkbox is checked --> 
    <OBJECT id="swf" style="z-index:2; position:absolute; top:20%; left:15%;" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="90%" HEIGHT="70%" id="rice" ALIGN=""><PARAM NAME=movie VALUE="rice.swf"><PARAM NAME=quality VALUE=low><EMBED src="rice.swf" quality=low bgcolor=#EEEEEE WIDTH="90%" HEIGHT="90%" NAME="rice" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED> </OBJECT> 

<center><h1>Logo Here!</h1><br> 
</center> 
        <span id="a1" style="display: block;"><div class="texts" > 
            <div class="title" > 
        <strong>Step 1</strong><br><br> 
       </div> 

<div class="rice">Content<br></div> 
<label class="label_check" > 
    <input name="sample_check1" id="sample_check1" value="1" type="radio" onclick="showStuff('a2')" /> 
Done? 
    </label></div></span> 
<br> 
        <span id="a2" style="display: none;"><div class="texts"> 

            <div class="title" > 
        <strong>Step 2</strong><br><br> 
       </div> 

<div class="rice">Content<br></div> 
<label class="label_check" > 
    <input name="sample_check2" id="sample_check2" value="1" type="radio" onclick="showStuff('a3');" /> 
Done? 
    </label> 
       </div></span> 
<br> 
        <span id="a3" style="display: none;"><div class="texts"> 

            <div class="title" > 
        <strong>Step 3</strong><br><br> 
       </div> 
        <div class="rice">Content<br></div> 
<label class="label_check" > 
    <input name="sample_check3" id="sample_check3" value="1" type="radio" onclick="showStuff('stage');setTimeout(katana, 10000, 'swf');setTimeout(friedrice, 12000, 'chopsticks', 'surprise');" /> 
Ready? 
    </label> 
       </div></span> 

     <span id="stage" style="display:none;"> 
      <img src="images/dot.png" style=" position:absolute; left:44%; top:20%;"/> 
     </span> 


        <script> 
     $('body').hide(); 
     $('body').fadeIn(1000); 
    </script> 
</div> 
<div id="surprise"> <!-- This is the "hidden" content that is displayed 12 seconds after the checkbox is checked --> 
<center> 
<p> i jo</p> 
<embed src="scare.mp3" autoplay="true" loop="true" height="240" width="100"></embed> 
</div> 
</center> 
</body></html>