Ich versuche, den Wert von Tabellenelement id = "questionLoc" zu einer Frage zu ändern, die ich in einem Array platziert habe. HTML unten ...Ändern Sie HTML-Text mit JavaScript
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<script type="text/javascript" src="main.js"></script>
<script type="text/javascript" src="javascript/jquery-1.3.2.min.js"></script>
<title>Game of Thrones Trivia Quiz</title>
</head>
<body>
<header>
<h1>Game of Thrones Trivia Quiz</h1>
</header>
<form action="" name="mainForm">
<p>Please choose the correct answer for the question given. Do so promptly - winter is coming.</p>
<table>
<tr>
<td id="questionLoc">
Question Location
</td>
</tr>
Javascipt Dokument ...
alert("hi");
var allQuestions = [];
function question(question, choices, answer) {
this.question = question;
this.choices = choices;
this.answer = answer;
}
var question1 = new question("Who is Sansa\'s mother?", ["Cercei", "Marjorie", "Catelin", "Lysa"], 2);
var question2 = new question("Who is Geoffrey\'s mother?", ["Cercei", "Marjorie", "Catelin", "Lysa"], 0);
var question3 = new question("Who is Robert\'s mother?", ["Cercei", "Marjorie", "Catelin", "Lysa"], 3);
allQuestions.push(question1, question2, question3);
$(document).ready(function() {
$('#button').click(function {
$('R1').html("Response 1")
});
});
var qLoc = document.getElementById("questionLoc").innerHTML;
qLoc = allQuestions[0].question;
Die alert ("Hallo") ist ein Test, und erscheint nur, wenn ich meine jQuery Kommentar aus. Der Text "questionLoc" ändert sich trotz der Zeile "getDocumentByID" nicht. Irgendwelche Gedanken darüber, warum der Code nicht ausgeführt wird, würden geschätzt werden! Vielen Dank.
Stellen Sie jsfiddle. –
Zusätzlich zu anderen möglichen Problemen ist $ ('R1') wahrscheinlich kein gültiger Selektor. Ein Punkt oder Hash fehlt. –