0

我有这个代码:

<script language="javascript">
var noun=["cat","mat","rat"];
var verb=["like","is","see","sees"];
var object=["me","a+noun","the+noun"];
var subject=["I","a+noun","the+noun"];
var sentence=(subject+verb+object);

function checkCorrectness(){
    var input=document.getElementbyId("userInput");
    if(input==sentence)
        {
        alert("congratulations your sentence is correct");
        }
    else if(input=="null"||"")
        {
        alert("your entered a blank text, please enter sentence");
        }
    else{
        alert("Sorry, Your sentence is incorrect, your sentence should be in the form of a subject, verb and object. please try again");
        }
};
</script>
</head>
<body>
<h1><font size="3" color="black" face="comic sans ms">Welcome to Micro English</font></h1>
<h2><font size="2" color="blue" face="comic sans ms">Please Enter a sentence in micro English in the box below</font></h2>

<form onsubmit="checkCorrectness();">
<input type="text" name="input" id="userInput"/>
<input type="submit"value="go"/>
</form>

但是当我点击“开始”按钮时没有任何反应。可能是什么问题?我曾尝试更改输入的类型,但它从未运行过,我有一个类似的程序确实运行过,但我只是在这里解决了问题。请帮忙

4

3 回答 3

1

这段代码正在工作..

 <script language="javascript">
var noun=["cat","mat","rat"];
var verb=["like","is","see","sees"];
var object=["me","a+noun","the+noun"];
var subject=["I","a+noun","the+noun"];
var sentence=(subject+verb+object);

function checkCorrectness(){
    var input=document.getElementById("userInput").value;
    if(input==sentence.length)
        {
        alert("congratulations your sentence is correct");
        }
    else if(input==null || input =="")
        {
        alert("your entered a blank text, please enter sentence");
        }
    else{
        alert("Sorry, Your sentence is incorrect, your sentence should be in the form of a subject, verb and object. please try again");
        }
};
</script>
</head>
<body>
<h1><font size="3" color="black" face="comic sans ms">Welcome to Micro English</font></h1>
<h2><font size="2" color="blue" face="comic sans ms">Please Enter a sentence in micro English in the box below</font></h2>

<form onsubmit="checkCorrectness();">
<input type="text" name="input" id="userInput"/>
<input type="submit"value`enter code here`="go"/>
</form>
于 2013-08-15T19:24:03.800 回答
0

你应该做这个:

var input=document.getElementbyId("userInput");
 var inputtext=input.value;

现在使用 inputtext 代替 input 进行比较。

要不就:

var input=document.getElementbyId("userInput").value;
于 2013-08-15T19:14:59.403 回答
0

getElementbyId缺少资本B- 应该是getElementById

我在评论中提到的事情也需要修复。

于 2013-08-15T19:11:23.670 回答