我已经在 html 上创建了一个表单,并将文本框文本发送到 servlet 进行处理,现在我的困惑是如何使用 jquery 和 java servlet 连接并验证该表单。
有人可以帮我吗
最佳答案
嗯...没有一些代码和您需要的更具体的细节,我只能给您一些提示。您可以使用类似以下代码的代码在客户端验证您的表单:
<form id="someForm" action="someURL">
<input id="input1" type="text" value=""/>
<input id="input2" type="text" value=""/>
...
<input id="inputn" type="text" value=""/>
</form>
<script type="text/javascript">
$("#someForm").submit(function(){
var valid = true;
if ($("#input1").val() == "") {
alert("Please enter information for input1");
valid = false; // prevent the form from being submitted
} // use else, if put more conditions here
return valid;
});
</script>
希望对你有帮助!
关于java - 我如何连接并验证 javascript 和 java servlet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7205644/