我对使用 jQuery 的 validate() 很陌生,所以也许我遗漏了一些明显的东西。
当我将表单/验证函数粘贴到 jsfiddle 时,它会正确验证。可以在http://jsfiddle.net/AmLcV/6/看到。
但是在我的实时网页上,无论如何,表单总是提交。这是在http://students.cse.unt.edu/~haw0038/4890/index.php。
HTML:
<form id="form1" method="post" action="javascript:alert('form submitted')">
<p>• Which version would you like to run?<br/>
<input id="variables" type="radio" name="version" value="variables" />
<label for="variables">Individual Variables</label><br/>
<input id="array" type="radio" name="version" value="array" />
<label for="array">Array Representation</label>
</p>
<p>• Would you like to find the largest, or smallest number?<br/>
<input id="large" type="radio" name="type" value="large" />
<label for="large">Largest</label><br/>
<input id="small" type="radio" name="type" value="small" />
<label for="small">Smallest</label>
</p>
<p>• Use random numbers, or input your own?<br/>
<input id="random" type="radio" name="numSelect" value="random" />
<label for="random">Generate random numbers for me</label><br/>
<input type="text" name="nums" id="nums" value="How many? (2 to 10)" disabled="disabled"/><br/><br/>
<input id="userDef" type="radio" name="numSelect" value="userDef"/>
<label for="userDef">I want to use my own numbers</label><br/>
<input id="userNums" type="text" name="userNums" disabled="disabled"/><br/><br/>
<input type="submit" name="submit" value="Start the Simulation!" />
</p>
</form>
JS:
$(function(){
$('#form1').validate({
rules:{
version: "required",
type: "required",
numSelect: "required",
userNums: "required"
}
});
});
任何想法为什么会发生这种情况?我不知道我在这里缺少什么,或者是什么导致了它。
提前致谢。