2010-09-27 116 views
0

下面的代碼工作良好,但我將它放入DRUPAL頁面,我希望它刷新「DIV」而不是整個頁面。有人可以幫忙嗎?謝謝!如何在javascript中而不是整個頁面中刷新Div?

  document.write("<div class='box1'><center><h1>Telling Time Worksheets</h1></center><div class='box_number_holder'>") 
var nums = [01,02,03,04,05,06,07,08,09,10,11,12]; 
var gen_nums = []; 

function in_array(array, el) { 

    for(var i = 0, j = array.length; i < j; i++) 
     if(array[i] == el) return true; 
    return false; 

} 

function get_rand(array) { 
    var rand = array[Math.floor(Math.random()*array.length)]; 
    if(!in_array(gen_nums, rand)) { 
     gen_nums.push(rand); 
     return rand; 
    } 
    return get_rand(array); 
} 

for(var i = 0; i < 9; i++) { 
    document.write("<div class='box_numbers'><center>What Time is it?" + get_rand(nums) + "</center></div>"); 
} 

謝謝!

+0

代碼格式按鈕? – alex 2010-09-27 05:20:48

+1

我認識到這個代碼。那是我的*代碼嗎? – 2010-09-27 05:22:40

+0

是的,您的答案消失了,所以我無法宣傳它 – Vic 2010-09-27 05:24:45

回答

1

創建,通過所有的動態創建div元素的循環功能:

function refreshDivs() { 
    $('.box_numbers > center').each(function() { 
     $(this).html('What Time is it? ' + get_rand(nums)); 
    }); 
} 
相關問題