我动态创建了许多文本标签,并将它们添加到第一个html页面,并试图在用户移至第二个页面时检索这些值。由于某些原因,无法检索html值。我已经玩了一段时间了,没有任何运气。
var ReadingComprehensionExperiemnt = function(remaining){
psiTurk.showPage('stage1.html');
text = "Many years ago I went to Amsterdam as an art student, to be trained under the auspices of the then famous portrait painter Kruseman. Very soon I was admitted to the master's studio, and beheld with admiration the portraits of the distinguished personages he was painting at the time."
d3.select("#passage")
.style("text-align","center")
.style("font-size","25px")
.style("font-weight","400")
.style("margin","20px")
.text(text);
$("#next").click(function () {
var sel = document.getElementById('sentence');
var numLines = sel.options[sel.selectedIndex].value;
psiTurk.showPage('stage2.html');
d3.select("#passage")
.style("text-align","center")
.style("font-size","18px")
.style("font-weight","400")
.style("margin","20px")
.text(text);
var elm = document.getElementById( 'user-input' );
for (i=0;i<numLines;i++){
var lab;
if (i==0){
lab="What: ";
} else{
lab="Cause: ";
}
div = document.createElement( 'div' );
div.innerHTML = `<center>${lab}<input id='textfield_${i}' type='text' value='' size="100"></center>`;
elm.appendChild( div ); }
$("#next2").click(function () {
psiTurk.showPage('stage3.html');
var data=[text,numLines];
for (i=0;i<numLines;i++){
var name = "textfield_" + i;
var input = document.getElementById(name).value;
alert(input);
}
});
});
}