jQuery验证 - > TypeError:'undefined'不是函数(评估'this.each')

时间:2013-06-29 06:18:37

标签: javascript jquery validation

我正在使用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:'undefined'不是函数(评估'this.each')

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

jQuery版本: v1.10.1

验证插件版本: 1.9.0

注意:此页面中还有其他表单,它们具有单独的ID,字段名称也不冲突。我也正确检查,表格没有重叠。为了增加更多的挫折感,同一组文件可以在我网站的其他页面中使用。

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

非常感谢提前。

0 个答案:

没有答案