2

それらを表示するために、ローカルストレージ変数に格納されている値を取得しようとしています!! しかし、ここでの問題は、値の表示が即座に行われることです。つまり、最初にページをロードしたときに何も表示されず、ページを更新するたびに次の値が表示されます。

function ChoixDeQuestion (){

var ide=window.sessionStorage.getItem('idenq');
GetQuest(10);//--> this function store some values in the 'questions' var
var storedQuest=JSON.parse(window.localStorage['questions']);
var i;

for ( i = 0; i < storedQuest.length; i++) 
    {
var newdiv = document.createElement('div');
 switch(storedQuest[i].type) {
      case 'text':
           newdiv.innerHTML += "<br> Question " + (i + 1) + " : "+storedQuest[i].text+" ?  <br><br><textarea name='quest"+(i + 1)+"' rows=4 cols=40 >type here...</textarea>" ;

           break;
      case 'simple':
           var questId=storedQuest[i].id;
           GetChoix(questId);
           var storedChoix=JSON.parse(window.localStorage['choices'+questId]);

           newdiv.innerHTML += "<br> Question " + (i + 1) + " : "+storedQuest[i].text+" ? <br><br>";
           for (var j = 0; j < storedChoix.length; j++) {
           newdiv.innerHTML += "  " + (j + 1) +"- "+storedChoix[j].text+ " <input type='radio' name='choix"+(j + 1)+"'>";

           }
           break;
      case 'multiple':
           var questId=storedQuest[i].id;
           GetChoix(questId);
           var storedChoix=JSON.parse(window.localStorage['choices'+questId]);

           newdiv.innerHTML += "<br> Question " + (i + 1) + " : "+storedQuest[i].text+" ? <br><br>";
           for (var j = 0; j < storedChoix.length; j++) {
           newdiv.innerHTML += " " + (j + 1) +"- "+storedChoix[j].text+ " <input type='checkbox' name='choix"+(j + 1)+"'>";

            } 
            break;
 document.getElementById('results').appendChild(newdiv);

    }
 }

このメソッドは

 $(document).ready(function() { ChoixDeQuestion();});

では、ページがロードされたときに同時に表示されるすべての値を取得するにはどうすればよいですか??

4

0 に答える 0