0

我正在使用 jQuery 验证来验证表单。表单如下所示:

    <div id="app_install_off" class="edit-ph mtop20"><h3 class="stakes-form-title-saved">APP INSTALL <span class="blue-txt"><!--(saved)--></span></h3><a href="#"><img border="0" align="right" style="margin:0 15px 0 0" src="../img/edit-button.png"></a></div>
<div id="app_install_on" class="appinstall-ph">
<form novalidate="novalidate" action="/sweepstakes/campaignstep2" id="AppInstallTaskCampaignstep2Form" method="post" accept-charset="utf-8"><div style="display:none;"><input name="_method" value="POST" type="hidden"></div>            <div class="form-header"><h3 class="stakes-form-title">APP INSTALL <span class="greentext">(not saved)</span></h3></div>
        <div class="form-content-area">
            <div class="app-field-ph">
                <ul class="apps-form">
                    <li class="f-label">App Name</li>
                    <li class="input-ph"><div class="input text"><input name="data[AppInstallTask][task_title]" class="appsform-field" id="AppInstallTaskTaskTitle" border="0" type="text"></div></li>
                </ul>
                <ul class="apps-form whitebg">
                    <li class="f-label">Package Name</li>
                    <li class="input-ph"><div class="input text"><input name="data[AppInstallTask][app_package_name]" class="appsform-field" value="Example: Com.MyAppPackage" id="AppInstallTaskAppPackageName" border="0" type="text"></div></li>
                </ul>
                <ul class="apps-form">
                    <li class="f-label">Market URL</li>
                    <li class="input-ph"><div class="input text"><input name="data[AppInstallTask][web_url]" class="appsform-field" id="AppInstallTaskWebUrl" border="0" type="text"></div></li>
                </ul>
            </div>
            <div class="save-clear-ph">
                <a href="#"><img src="../img/clear-button.png" border="0"></a>&nbsp;&nbsp;&nbsp;
                <a href="Javascript:void(0)"><img id="app_install_submit" src="../img/save-button.png" border="0"></a>
                <input name="data[AppInstallTask][task_type]" value="Download an App" id="AppInstallTaskTaskType" type="hidden">                </div>
        </div>
    </form>
</div>
</div>

<!-- The next similar block -->
<div id="like_fb_on" class="appinstall-ph mtop20">
    <form action="/sweepstakes/campaignstep2" id="LikeFbTaskCampaignstep2Form" enctype="multipart/form-data" method="post" accept-charset="utf-8"><div style="display:none;"><input type="hidden" name="_method" value="POST"/></div>            <div class="form-header"><h3 class="stakes-form-title">LIKE FACEBOOK PAGE <span class="greentext">(not saved)</span></h3></div>
        <div class="form-content-area">
            <div class="app-field-ph">
                <ul class="apps-form">
                    <li class="f-label">Campaign Option Name</li>
                    <li class="input-ph"><div class="input text"><input name="data[LikeFbTask][task_title]" class="appsform-field" border="0" type="text" id="LikeFbTaskTaskTitle"/></div></li>
                </ul>
                <ul class="apps-form whitebg">
                    <li class="f-label">Facebook Page URL</li>
                    <li class="input-ph"><div class="input text"><input name="data[LikeFbTask][web_url]" class="appsform-field" border="0" type="text" id="LikeFbTaskWebUrl"/></div></li>
                </ul>
            </div>
            <div class="save-clear-ph">
                <a href="#"><img src="../img/clear-button.png" border="0"></a>&nbsp;&nbsp;&nbsp;
                <a href="#"><img src="../img/save-button.png" border="0"></a>
                <input type="hidden" name="data[LikeFbTask][task_type]" value="Like Facebook Page" id="LikeFbTaskTaskType"/>                </div>
        </div>
    </form>    
</div>

点击图片(id = "app_install_submit"),我正在提交表单。jQuery验证实现如下:

$(document).ready(function() {
    jQuery('#AppInstallTaskCampaignstep2Form').validate({
        rules: {
            "data[AppInstallTask][task_title]": {
                required: true
            },
            customMessage: "required",
        }
    });
});

点击事件如下:

$('#app_install_submit').click(function(){
        $('#AppInstallTaskCampaignstep2Form').submit();
    });

它也包含在 ready() 中。

这是第一次工作,突出显示具有错误类别的字段,并且消息附加在标签中。任何进一步的点击都会产生这个“噩梦”错误:

TypeError:“未定义”不是函数(评估“this.each”)

此外,虽然表单实际上得到了正确验证,但它拒绝提交。

jQuery版本:v1.10.1

验证插件版本:1.9.0

注:此页面还有其他表单,它们有单独的id,字段名称也不冲突。此外,我已正确检查,表格没有重叠。更令人沮丧的是,这组文件也适用于我网站的其他页面。

期待一个指针,我可能会出错。

提前谢谢了。

4

0 回答 0