繁体   English   中英

我如何连接和验证javascript和Java servlet

[英]how do i connect and validate javascript and java servlet

我已经在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>

希望能帮助到你!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM