英语老师在这里尝试使语法小部件工作。
我需要能够在答案中加入撇号。每当我输入一个时,将其变为绿色或红色的功能都不起作用。
以下是我尝试做的一个例子:
<!DOCTYPE html>
<html>
<head>
<title>Connect</title>
<style>
form{font-family:"Verdana";font-size:18px;}
input{font-family:"Verdana";font-size:18px;}
button{font-family:"Verdana";font-size:18px;font-
weight:bold;background:blue;color:white;box-shadow: 10px 10px 5px #888888;border:none}
</style>
</head>
<body>
<form>
1. Parkour is an athletic discipline <input id="1" type="text" placeholder="that / which /
who"/> developed from obstacle course training.
<p>
2. Athletes <input id="2" type="text" placeholder="that / which / who"/> come from all
over the world, will meet at the XGames next month.
<p>
<p>
<button type="button"
onclick="evalAnswer('1','that','which');evalAnswer('2','who')">CHECK</button><br>
<!-- If you need a new sentence, now you just need to increment the id's number and -->
<!-- change the button: ...onclick="evalAnswer('5','may','can','should')... -->
<!-- note that you can add more than one right answer -->
<!-- Example: -->
<!-- 6. You <nbsp&><input id="6" type="text" /> to see a doctor! -->
<!-- <button type="button" onclick="evalAnswer('6','have
to','need','should')">CHECK</button> -->
</form>
<script>
function evalAnswer() {
var id = arguments[0];
var answer = document.getElementById(id).value;
for (var i = 1; i < arguments.length; i++) {
if(arguments[i] == answer ){
document.getElementById(id).style.color = "green";
break;
} else {
document.getElementById(id).style.color = "red";
}
}
}
</script>
</script>
</body>
</html>
答案 0 :(得分:0)
您可以通过在其前面添加反斜杠\
来转义撇号。
onclick="evalAnswer('1','that\'s','which');evalAnswer('2','that\'s')"
<强> jsFiddle example 强>