2012-09-27 21 views
0

下降HTML5測驗結果我試圖發展與拖放一個測驗片段,並用這個代碼,其中其始終顯示的結果1,結果不增加最終.....阻力和不增加

我試了很多辦法,但它不是遞增.....

的javascript:

這裏是我的代碼,我在

<script> 
    function allowDropi(ev) 
    { 
     ev.preventDefault(); 
    } 

    function dragi(ev) 
    { 
     ev.dataTransfer.setData("Text",ev.target.id); 
    } 

    function dropi(ev) 
    { 
     ev.preventDefault(); 
     var data=ev.dataTransfer.getData("Text"); 
     ev.target.appendChild(document.getElementById(data)); 

     result1=0; 

     if(ev.dataTransfer.getData("Text")==="drag2i") 
     { 
      result1++; 

     } 


     if(ev.dataTransfer.getData("Text")==="dra2i") 
     { 
      result1++; 
     } 


     if(ev.dataTransfer.getData("Text")==="dr2i") 
     { 
      result1++; 
     } 


     if(ev.dataTransfer.getData("Text")==="2i") 
     { 
      result1++; 
     } 


     if(ev.dataTransfer.getData("Text")==="d2i") 
     { 
      result1++; 
     } 

     document.getElementById('boldStuff6').innerHTML = result1; 
    } 

    alert(result1); 

    </script> 

我要去哪裏錯了,請檢查米,用來ycode並幫助我得到結果...

+0

您好,我需要一個更青睞的是我cannt限制下拉框,以一個形象ü可以提出任何更改,請... – Maddy

回答

1

原因是,每次您調用此函數結果正在設置爲0「result1 = 0」,然後您將提高它之後。

如果你想保持計數的結果,你會努力使結果作爲函數的一個屬性。

,而不是「RESULT1 = 0」地址:

this.result1 = (this.result1 ) ? this.result1 : 0; // this will make sure it keeps old stored values from last time you call the function. 

,改變你的增量器爲以下內容:

this.result1++; // or you can use ++this.result1; or even this.result1+=1; 

我希望這能回答你的問題。

感謝, 米特雷

+0

感謝重播的工作我的錯,我沒有看到它。 ....你的真棒兄弟.... – Maddy

+0

嗨,我需要一個更多的青睞,我不能限制下拉框到一個圖像可以ü建議任何變化,請... – Maddy

+0

你可以請嘗試解釋更好的問題嗎? –