【发布时间】:2017-02-08 20:59:54
【问题描述】:
我正在尝试将表元素 id="questionLoc" 的值更改为我放置在数组中的问题。下面的 HTML...
<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 文档...
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;
alert("hi") 是一个测试,只有在我注释掉我的 jQuery 时才会出现。尽管有 'getDocumentByID' 行,但“questionLoc”文本不会改变。任何关于为什么代码不执行的想法将不胜感激!谢谢。
【问题讨论】:
-
提供jsfiddle。
-
除了其他潜在问题之外,$('R1') 不太可能是一个有效的选择器。缺少点或哈希。
标签: javascript jquery html dom text