2013-03-28 24 views
0

即時通訊嘗試做一個動態測驗與HTML的CSS和jQuery,當我嘗試更改使用jquery <p id=question></P>什麼都沒有發生,我離開你我的HTML和jQuery代碼。用jquery改變文本

<!DOCTYPE html> 
<html lang='es'> 
<head> 
<meta charset='UTF-8'> 
<title>Dynamic Quiz</title> 
<link rel="stylesheet" type="text/css" href="css/normalize.css"> 
<link rel="stylesheet" type="text/css" href="css/estilos.css"> 
<script type="text/javascript" src="js/jquery.js"></script> 
<script type="text/javascript" src="js/prefixfree.js"></script> 
<script type="text/javascript" src="js/codigo.js"></script> 
</head> 
<body> 
<header> 
    <hgroup> 
     <h1>This is my Dynamic Quiz</h1> 
     <h2>Using html5/css/javascript</h2> 
    </hgruop> 
</header> 

<section id='description'> 
    <p>This quiz is compossed by 10 questions, you have to answer at least 7 
     from 10 to pass the exam.</p> 
    <h2>Lets start!</h2> 
</section> 

<div id='questions-number'> 
    <p>Question <span id='current-question'>1</span> of <span>10</span> </p> 
</div> 

<section id='questions'> 
    <p id='question'></p> 

    <ul> 
     <li><input type='checkbox' /><label>answer0</label></li> 
     <li><input type='checkbox' /><label>answer1</label></li> 
     <li><input type='checkbox' /><label>answer2</label></li> 
     <li><input type='checkbox' /><label>answer3</label></li> 
    </ul> 
</section> 

<div id='next'> 
    next 
</div> 
</body> 
</html> 

,這是我的jQuery代碼....

$(document).on('ready', ready); 
function ready(){ 
var allQuestions = 
[ 
    { 
     question1: "Whats my real name?", 
     choices1: ["Jhonnatan", "Alberto", "Tatan","Jaime"], 
     answer1: 0 
    }, 

    { 
     question2: "Who is Colombia's president?", 
     choices2: ["Alvaro Uribe", "Andres Pastrana", "Juan Manuel Santos","Tatan"], 
     answer2: 2 
    }, 

    { 
     question3: "My favorite super heroe?", 
     choices3: ["Batman", "Flash", "Tatan","Javascript"], 
     answer3: 3 
    }, 

    { 
     question4: "Wich sports do i practice?", 
     choices4: ["Climbing", "Swimming", "Programming","Running"], 
     answer4: 0 
    }, 

    { 
     question5: "Whats my dad's name?", 
     choices5: ["Alberto", "Jorge", "Javier","Jose"], 
     answer5: 1 
    }, 

    { 
     question6: "Whats my favorite color?", 
     choices6: ["Red", "Purple", "Blue","All"], 
     answer6: 2 
    }, 

    { 
     question7: "My favorite alcoholic drink", 
     choices7: ["Vodka", "Aguardiente", "Rum","Tekila"], 
     answer7: 3 
    }, 

    { 
     question8: "Whats my favorite kind of music?", 
     choices8: ["Hardcore", "Reggaeton", "Salsa","Programming"], 
     answer8: 0 
    }, 

    { 
     question9: "How many qestions has this quiz??", 
     choices9: ["20", "8", "10","12"], 
     answer9: 2 
    }, 

    { 
     question10: "My favorite programming lenguage?", 
     choices10: ["Ruby", "Arduino", "Python","Javascript"], 
     answer10: 3 
    } 
]; 
$('question').text('hola mundo!'); 
console.log($('question')); 

}

我IHAVE與對象內部的數組,每個對象包含的問題,更多鈔票的答案和正確答案我像所有這一切與jquery dinamically到我的HTML和當按下一個按鈕更改問題不好意思,如果有人可以幫助我

+0

我試着用相同的代碼改變所有p標籤和所有h2標籤的文本,它的工作,丹特知道爲什麼它不工作的問題編號 –

+0

記得標記一個接受的答案,如果當你得到的時間! :-) –

回答

1

question是不是一個元素,它是一個ID。要選擇ID,您可以使用#

爲了解決這個問題,只需更改$('question')$('#question')

+0

不能相信的,這仍然發生在我身上... :( –

+0

它發生在我們所有人時不時!:-) –

1

你錯過了id選擇。嘗試:

$("#question").text("hola mundo!"); 
0

您需要使用$('#question')來通過ID引用元素。只是$('question')將是像​​的元素, $('.question')將是一個類。