我正在構建一個簡單的益智應用程序,並使用JavaScript library來拖放這些碎片。但我無法弄清楚如何檢查所有部件是否在正確的位置。計算JavaScript中的事件
到目前爲止,我已經得到了什麼是
// create the draggable puzzle piece
var p1=document.getElementById('piece1');
new webkit_draggable(p1);
p1.className = 'ps1';
// create an array to count the pieces placed correctly
var countArray = new Array();
// create the dropspot, link it to the puzzle piece and add an element to the array to count. Finally kill the dropspot
var p1p1 = webkit_drop.add('droppiece1',{accept : ['ps1'], onDrop : function(){countArray.push("a");webkit_drop.remove('droppiece1')}});
// piece has been placed correctly.
if(countArray.length = 1){
alert('Piece placed correctly');
};
我遇到的問題是,從計數功能火災警報立即。 我該如何解決這個問題?
對!對不起,這真是愚蠢的我。我試過使用==,但現在警報根本沒有發射。感謝您及時的回覆。 – 2012-03-08 17:49:26
仍然沒有運氣?看我的編輯。 – 2012-03-08 18:28:39
明天進行測試,但我認爲你有一些東西。每當一塊作品正確放置時,我可以檢查計數。當所有東西都放置正確後,警報將會觸發。如果我正確閱讀它。 非常感謝! – 2012-03-08 23:38:03