我是博洛尼亚大学(意大利)的学生
我使用html和javascript创建了一个简单的游戏。目标是尽快使用键盘上的箭头键到达路径的末尾。
我会将此游戏插入Qualtrics调查中。 我试图在html选项卡和Rich Content Editor的源选项卡中输入html但结果是一样的:当我使用预览问题时,我看到了正确的模板但当然我无法测试javascript脚本,当我使用预览调查时,我看不到正确的模板,只看到一些文字。
我想知道我是否应该使用"添加javascript",我还没有javascript脚本,但是里面有javascript的html。
感谢您的帮助。费德里科
该脚本有效,请参阅http://federicoforte.altervista.org/testDestra.html
这里有代码:
<html>
<head><title>Un piccolo gioco</title>
<STYLE type=text/css>#board TD {
FONT-SIZE: 2pt; WIDTH: 30pt; HEIGHT: 30pt
}
TD.foot {
FONT-SIZE: 10pt
}
#board TD.start {
BORDER-TOP: black 2px solid; FONT-SIZE: 8pt; BACKGROUND: white; BORDER-LEFT: black 2px solid; COLOR: red; TEXT-ALIGN: center;
}
#board TD.end {
FONT-SIZE: 8pt; COLOR: green; TEXT-ALIGN: center
}
#messaggio {
PADDING-RIGHT: 0pt; PADDING-LEFT: 0pt; PADDING-BOTTOM: 0pt; MARGIN: 0pt; PADDING-TOP: 0pt; TEXT-ALIGN: center
}
</style>
<script language=JavaScript>
var percorso = new Array()
for (var righe = 0; righe < 13; righe++)
percorso[righe]= new Array()
percorso[0][0] = new Array(1,0,0,0,0,0,0,0,0,0,0,0)
percorso[1][0] = new Array(0,0,0,0,0,0,0,0,0,0,0,0)
percorso[2][0] = new Array(0,0,1,1,1,1,1,1,1,0,0,0)
percorso[3][0] = new Array(0,0,0,1,1,1,1,1,0,0,0,0)
percorso[4][0] = new Array(0,0,1,1,1,1,1,0,0,0,1,1)
percorso[5][0] = new Array(0,0,0,0,0,0,0,0,0,0,0,0)
percorso[6][0] = new Array(0,0,0,1,1,1,1,0,0,0,0,0)
percorso[7][0] = new Array(0,0,0,0,1,1,1,1,0,0,0,0)
percorso[8][0] = new Array(0,0,0,0,0,0,0,0,0,0,0,0)
percorso[9][0] = new Array(0,0,0,0,0,0,0,0,0,1,0,0)
percorso[10][0] =new Array(0,0,0,0,0,0,0,0,1,1,1,0)
percorso[11][0] =new Array(0,0,0,0,0,0,0,0,0,0,0,0)
percorso[12][0] =new Array(0,1,1,0,0,0,0,0,0,0,0,0)
percorso[0][1] = new Array(1,0,0,0,0,0,0,0,0,0,0,0)
percorso[1][1] = new Array(1,0,0,0,0,0,0,0,0,0,0,0)
percorso[2][1] = new Array(1,1,0,0,0,0,0,0,1,0,0,0)
percorso[3][1] = new Array(1,1,0,0,0,0,0,1,1,0,0,0)
percorso[4][1] = new Array(1,0,0,0,0,0,1,1,1,1,0,1)
percorso[5][1] = new Array(1,0,0,0,0,0,1,1,1,1,1,1)
percorso[6][1] = new Array(1,0,1,0,0,0,0,1,1,1,1,1)
percorso[7][1] = new Array(1,0,1,1,0,0,0,1,1,1,1,1)
percorso[8][1] = new Array(1,0,1,1,0,0,0,1,1,1,1,1)
percorso[9][1] = new Array(1,0,1,1,0,0,0,1,0,0,1,1)
percorso[10][1] = new Array(1,0,1,1,0,0,0,0,0,0,1,1)
percorso[11][1] = new Array(1,0,1,1,0,0,0,0,0,0,1,1)
percorso[12][1] = new Array(0,0,0,1,0,0,0,0,0,0,1,1)
var lati = new Array("border-top","border-right")
var t0=0
var t1=0
var errori=0
function avanza(){
if (!dentro) return
if (coordRiga==0 && coordCol==0)
t0=performance.now()
switch (event.keyCode) {
case 37: //sinistra
if (percorso[coordRiga][1][coordCol-1]==0) {
if (prosegui(board.rows[coordRiga].cells[coordCol-1]))
messaggio.innerText="Sinistra"
coordCol--
document.all.board.rows[coordRiga].cells[coordCol].style.backgroundColor ="green"
} else {
messaggio.innerText="Attento, hai sbagliato percorso"
errori++ }
break;
case 38: //su
if (percorso[coordRiga][0][coordCol]==0) {
if (prosegui(board.rows[coordRiga-1].cells[coordCol]))
messaggio.innerText="Su"
coordRiga--
document.all.board.rows[coordRiga].cells[coordCol].style.backgroundColor ="green"
} else {
messaggio.innerText="Attento, hai sbagliato percorso"
errori++ }
break;
case 39: //destra
if (percorso[coordRiga][1][coordCol]==0) {
if (prosegui(board.rows[coordRiga].cells[coordCol+1]))
messaggio.innerText="Destra"
coordCol++
document.all.board.rows[coordRiga].cells[coordCol].style.backgroundColor ="green"
} else {
messaggio.innerText="Attento, hai sbagliato percorso"
errori++ }
break;
case 40: //giù
if (percorso[coordRiga+1]==null) {
errori++
messaggio.innerText="Attento, hai sbagliato percorso"
return }
if (percorso[coordRiga+1][0][coordCol]==0)
{
if (prosegui(board.rows[coordRiga+1].cells[coordCol]))
messaggio.innerText="Giù"
coordRiga++
document.all.board.rows[coordRiga].cells[coordCol].style.backgroundColor ="green"
} else {
messaggio.innerText="Attento, hai sbagliato percorso"
errori++ }
break;
}
if (document.all.board.rows[coordRiga].cells[coordCol].innerText=="end") {
t1=performance.now()
messaggio.innerText = "Molto bene, hai completato il percorso!\n "+"Hai impiegato: "+ (t1-t0)/1000+" secondi"+" con " +errori+ " errori."
dentro=false
stop=true
}
}
function prosegui(casella) {
if ((board.rows[coordRiga].cells[coordCol].style.backgroundColor =="green") && (casella.style.backgroundColor=='green')) {
messaggio.innerText="Stai tornando indietro"
errori++
board.rows[coordRiga].cells[coordCol].style.backgroundColor =""
return false
}
return true
}
</script>
</head>
<body bgColor="white">
<br>
<center>
<b>TEST di abilitá con la mano DESTRA</b>
<br>
Usa i tasti freccia per completare il percorso nel <b>minor tempo possibile</b>, attento però a non sbagliare scontrandoti con le pareti del percorso.
<br>Saranno memorizzati anche gli errori. </strong></p>
<br><p>
<TABLE id=board cellSpacing=0 cellPadding=0 align=center>
<script>
for (var riga = 0; riga<percorso.length; riga++) {
document.write("<TR>")
for (var col = 0; col<percorso[riga][0].length; col++) {
document.write("<TD STYLE='")
for (var cell = 0; cell<2; cell++) {
if (percorso[riga][cell][col]==1)
document.write(lati[cell]+": 2px black solid;")
}
if ((0==col) && (0!=riga))
document.write("border-left: 2px black solid;")
if (riga==percorso.length-1)
document.write("border-bottom: 2px black solid;")
if (riga==percorso.length-1 && col>=4 && col<11)
document.write("border-bottom: 2px white solid;")
if ((0==riga) && (0==col))
document.write(" background-color:yellow;' class=start>start</TD>")
else
if ((riga==percorso.length-1) && (col==percorso[riga][0].length-1))
document.write("' class=end>end</TD>")
else
document.write("'> </TD>")
}
document.write("</TR>")
}
coordRiga = 0
coordCol = 0
dentro = true
document.onkeydown=avanza;
</script>
</table>
<p id=messaggio></p>
</body>
</html>
Qualtrics&#39;支持告诉我,这可能是JFE的可配合性问题,是否可能?
感谢您的帮助
答案 0 :(得分:0)
您应该在加载页面后运行脚本。如果您可以共享代码,我可以尝试一下。