首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jquery验证2表单

Jquery验证2表单
EN

Stack Overflow用户
提问于 2011-08-05 03:37:05
回答 1查看 662关注 0票数 0

我遇到了一个jquery.validate的问题。我有2个表单在1页上。第一个表单是图像上传。ajax劫持了其中的帖子,上传图像并将图像返回到屏幕,然后使用图像名称更新第二个表单中的隐藏输入(VLogo)。

我想做的是,如果隐藏的输入是空的,当第二个表单被验证时,第一个表单中的元素被高亮显示。我希望这是有意义的。希望有人能帮我。下面是表单的一个示例:

表单1-图像上传表

代码语言:javascript
复制
<form class="logoform" id="mLogo">
    <tr>
        <td>
            <div id="logoContainer">
                <span id="logoarea"> <img id="thumb" width="100px" height="100px" src="images/logo_placeholder.gif" border="0"></span>
            </div>
        </td>
        <td colspan=2>
            <table cellspacing=0 cellpadding=3 border=0>
                <tr>
                    <td class="field"><input type="file" name="upload1" id="upload1" class="required"></td>
                </tr>
                <tr> 
                    <td align="right"><input type="submit" value="Add Logo" name="addlogo" class="ui-button ui-button-text-only ui-widget ui-state-default ui-corner-all"></td>
                </tr>
                <tr>
                    <td class="flabel"><label for="volvoLogo">Logo Upload</label></td>
                </tr>
            </table> 
        </td>
    </tr>           
</form>

表单2数据收集

代码语言:javascript
复制
<form id="customcal" action="processCal.cfm" method="post">
    <tr>
        <td colspan=3 class="flabel"><label for="c_dealerName">Dealer Name</label></td>
    </tr>
    <tr>
        <td colspan=3 class="field"><input type="text" name="c_dealerName" class="required"></td>
    </tr>
    <tr>
        <td class="flabel"><label for="c_phone">Phone</label></td>
        <td colspan=2 class="flabel"><label for="c_fax">Fax</label></td>
    </tr>
    <tr>
        <td class="field"><input type="text" name="c_phone" class="required phone"></td>
        <td class="field" colspan=2><input type="text" name="c_fax" class="required phone"></td>
    </tr>
    <tr>
        <td colspan=3 class="flabel"><label for="c_website">Website Address</label></td>
    </tr>
    <tr>
        <td colspan=3 class="field"><input type="text" name="c_website" class="required"></td>
    </tr>
    <input type="hidden" name="vLogo" id="vLogo" class="required">
    <tr> 
        <td colspan=3 align="right"><input type="submit" value="Submit" id="subform" name="submit" class="ui-button ui-button-text-only ui-widget ui-state-default ui-corner-all"></td>
    </tr>
</form>

到目前为止的JQUERY验证

代码语言:javascript
复制
$("#customcal").validate({
    invalidHandler: function(e, validator) {
        var errors = validator.numberOfInvalids();

        if (errors) {
            var message = errors == 1
                ? 'You missed 1 field. It has been highlighted below'
                : 'You missed ' + errors + ' fields.  They have been highlighted below';
            $("div.error span").html(message);
            $("div.error").show();
        } else {
            $("div.error").hide();
        }
    },
    onkeyup: false,     
    submitHandler: function() {         
        $("div.error").hide();                  
        form.submit();      
    }
});
EN

回答 1

Stack Overflow用户

发布于 2011-08-05 04:38:28

首先,您需要为表单提供一个通用的类.form_validate或其他通用的类。

然后在表单上执行each循环,并将验证应用于该项。

代码语言:javascript
复制
$('.form_validate').each(function(i, form){

    $(form).validate({

        /* Your Validation Code */

    });

});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6947542

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档