2016-08-18 2 views
-1

그래서 나는 자바 스크립트 배열을 가지고 배열에 나는이있다 : 배열의 설명 부분 집합에인쇄 자바 스크립트 배열 값은 제대로

var quiz = [{ 
    "question": "What is the greatest common factor of 105 and 126?", 
    "image": "", 
    "choices": ["3", "7", 
     "9", "21", "35" 
    ], 
    "correct": "21", 
    "conceptlink": "https://www.khanacademy.org/math/in-sixth-grade-math/playing-numbers/highest-common-factor/v/greatest-common-divisor", 
    "explanation": "In order to solve this question, you must factor each number into prime factors<h1>Height</h1>", 
}]; 

초점을. 인쇄 할 H1 요소가 있지만 대신 코드 대신 텍스트의 일부로 인쇄됩니다. 즉, 텍스트는 다음과 같습니다

enter image description here

대신 : 여기 enter image description here

전문가 기꺼이 할 것이다 JS에서 설명을

$('#explanation').html('<strong>Incorrect.</strong> ' + htmlEncode(quiz[currentquestion]['explanation'])); 

어떤 도움을 출력 코드의 고맙다 !!

+0

'htmlEncode()'가 올바르게 작동하는 것 같습니다. :) – Andreas

+0

불행히도. 나는 그것을 여러 번 시험했다. : ( –

답변

0

거의 가지고 있습니다. htmlEncode() 함수가 무엇인지 모르겠지만 사용하지 않으면 원하는 것을 제공해야합니다. 여기를 보여주는 jsbin가있다 : 당신은이 행해져 Yout 텍스트를 탈출 jQuery를 사용할 수 How to encode a string in JavaScript for displaying in HTML?

+0

고마워 .htmlEncode Jquery 네이티브 생각. 내가 소스 코드를 발견하고 함수를 편집! –

0

나는 당신이 그것에 대해 대해 HTMLEncode 필요가 있다고 생각하지 않습니다. 시도해 보시기 바랍니다 :

$('#explanation').html('<strong>Incorrect.</strong><span>').find('span').text(quiz[currentquestion]['explanation']))