将用户给定的输入与javascript中的字符串进行比较
comparing a user given input to a string in javascript
部分的代码。如果你所有的答案都是正确的,应该算2。在这方面我只是个新手。错误是当我打开浏览器并点击"检查?"时,没有任何反应。
<head>
<script language="javascript">
function checker()
{
var myscore = 0;
if(parseInt(document.quiz.num1.value) == 6)
{ myscore = (myscore + 1);}
else
{ myscore;}
if(document.quiz.num2.value == type of "dry" )
{ myscore = (myscore + 1);}
else
{ myscore;}
document.myform.thescore.value = myscore;
}
</script>
</head>
<body>
<form name="quiz">
How many feet are ther in 1 Fathom? <input type="text" id="num1">
<br>
What type of stones can never be found in the ocean? <input type="text" id="num2">
<br>
My Score: <input type="text" id="thescore"><br>
<input type="button" value="Check?" onClick="checker()">
</form>
</body>
答案如下:
<html>
<head>
<script lang="Java-Script">
var msg;
var sc;
function validateTest()
{
sc=0;
msg=document.frm.num1.value;
if(msg==6)
sc=sc+1;
msg=document.frm.num2.value;
if(msg=='dry')
sc=sc+1;
document.frm.thescore.value=sc;
return;
}
</script>
</head>
<body>
<form name="frm">
How many feet are there in 1 Fathom? <input type="text" name="num1"><br>
What type of stones can never be found in the ocean? <input type="text" name="num2"><br>
My Score: <input type="text" name="thescore"><br>
<input type="button" value="Submit" onclick="validateTest()">
</form>
</body>
</html>
我已经测试过了,它会工作的
相关文章:
- 反向字符串比较
- ExpressJS:奇怪的字符串比较
- 宽松的字符串比较
- 在angularJS中用字符串比较检查Json对象
- 在JavaScript中使用===进行字符串比较有意义吗
- 字符串比较显示从flash[:alert]检索到的字符串上的错误
- JSLint字符串比较错误应为'==='而是看到'=='
- 字符串比较在d3.rgb中不起作用
- 为什么这个字符串比较在Jest的期望中没有失败
- jQuery this.href 字符串比较不起作用
- 字符串比较不起作用
- 字符串比较与预期不符
- Javascript中的字符串比较不起作用
- 正则表达式(字符串比较)
- j查询字符串比较变量
- 字符串比较 JavaScript 中的失败
- 当字符串中存在空格时,字符串比较会给出错误的输出
- Ant JavaScript 相同的字符串比较给出了错误的结果,但 char compare 给出了字符串中每个字符的
- 正则表达式字符串比较忽略符号
- JavaScript 中的序号字符串比较