문제

내 IE와 크롬 브라우저는 프랑스어 문구 (Onload 함수)에서 영어 문구 (OnMousedown 기능)로 이동하고 프랑스어 문구 (OnMouseUp 함수)로 돌아갈 때 프랑스어 문구를 올바르게 표시하지 않습니다. 특정 문구의 마우스를 입력하면 프랑스어로 돌아가지 만 ô와 é의 특수 문자 ( ô 그리고 é ) 숫자 코드에서 ô 및 é로 변경하지 마십시오. 누구든지 왜이 일을하고 어떻게 고칠 수 있는지 말해 줄 수 있습니까?

다음은 내 JavaScript 코드입니다.

 /* 
   Function List: 
   eventSource(e) 
      Returns the source of an event in either event model 

   swapFE(phrase, pnum) 
      Changes a French phrase to the English version of that phrase. 

   swapEF(phrase, pnum) 
      Changes an English phrase ot the Frech version of that phrase. 

   setUpTranslation() 
      Insert the current week's french phrases into document and set up 
      event handlers for the phrases. 
*/ 

//Returns the source of an event in either event model 
function eventSource(e) { 
   var IE = document.attachEvent ? true:false; 
   var DOM = document.addEventListener ? true: false; 
   if (IE) return event.srcElement; 
   else if (DOM) return e.currentTarget; 
} 
//I added the function below to try and make it cross-browser compatible but it did not work....help! 
//function applysetUpTranslation(phrases[i],"click",swapFE(e),false) { 
//if (IE) phrases[i].attachEvent("on"+onmousedown, swapFE(e)); 
//else if (DOM) phrases[i].addEventListener(click,swapFE(e),true); 
//} 


function setUpTranslation() { 
   var IE = document.attachEvent ? true:false; 
   var DOM = document.addEventListener ? true: false; 
   var phrasesContainer = document.getElementById("phrases"); 
   var phrases= phrasesContainer.getElementsByTagName("p"); 

   for (i = 0; i<phrases.length; i++) { 
      phrases[i].number = i; 
      phrases[i].childNodes[1].innerHTML = french[i]; 
      phrases[i].childNodes[1].id = i; 

//childNodes[1] is the second span in the <p> array 
    if (IE) {
        phrases[i].childNodes[1].onmousedown = function() { swapFE(event); }; 
    } else {
        phrases[i].childNodes[1].onmousedown = swapFE; 
    }

    if (IE) {
        phrases[i].childNodes[1].onmouseup = function() { swapEF(event); };  
    } else {
        phrases[i].childNodes[1].onmouseup = swapEF;   
    } 

  } 

} 

//this function changes the French phrase to an English phrase. 
function swapFE(e) { 
       var phrase = eventSource(e); 
       //phrase.innerText = english[phrase.id]; 
       var parent = phrase.parentNode; 
       //childNodes[0] is the number of the phrase +1  
       var idnum = parent.childNodes[0]; 
       //parseInt takes a textstring and extracts it to make a number. Then you will subtract 1 from the number. 
       var phrasenum = parseInt(idnum.innerHTML)-1; 
       phrase.innerText = english[phrasenum]; 
       parent.childNodes[1].style.fontStyle= "normal"; 
       parent.childNodes[1].style.color = "rgb(155, 102, 102)"; 
  } 


function swapEF(e) { 
        var phrase = eventSource(e);
       //var phrase = e.srcElement;  
       //phrase.innerText = english[phrase.id]; 
       var parent = phrase.parentNode; 
       var idnum = parent.childNodes[0]; 
       var phrasenum = parseInt(idnum.innerHTML)-1; 
       phrase.innerText = french[phrasenum]; 
       parent.childNodes[1].style.fontStyle= "italic"; 
       parent.childNodes[1].style.color= "black"; 
} 

프랑스어 배열이있는 JS 코드는 다음과 같습니다.

    var english=new Array();
english[0]="This hotel isn't far from the Eiffel Tower.";
english[1]="What time does the train arrive?";
english[2]="We have been waiting for the bus for one half-hour.";
english[3]="This meal is delicious";
english[4]="What day is she going to arrive?";
english[5]="We have eleven minutes before the train leaves!";
english[6]="Living in a foreign country is a good experience.";
english[7]="Excuse me! I'm late!";
english[8]="Is this taxi free?";
english[9]="Be careful when you go down the steps.";

var french=new Array();
french[0]="Cet h&#244;tel n'est pas loin de la Tour Eiffel.";
french[1]="A quelle heure arrive le train?";
french[2]="Nous attendons l'autobus depuis une demi-heure.";
french[3]="Ce repas est d&#233;licieux";
french[4]="Quel jour va-t-elle arriver?";
french[5]="Nous avons onze minutes avant le d&#233;part du train!";
french[6]="Habiter dans un pays &#233;tranger est une bonne exp&#233;rience.";
french[7]="Excusez-moi! Je suis en retard!";
french[8]="Est-ce que ce taxi est libre?";
french[9]="Faites attention quand vous descendez l'escalier.";

도와 주셔서 정말 감사합니다.

도움이 되었습니까?

해결책

나는 당신이 사용해야한다고 생각합니다 innerHTML 특수 문자가 해석 될 수 있도록 :

phrase.innerHTML = french[phrasenum]; 

다른 팁

HTML/JavaScript 코드 파일이 생성되어 유니 코드를 사용하는 경우 ô 및 É 문자를 JavaScript에 넣고 문제없이 HTML을 넣을 수 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top