使用jqueryvalidation插件自动完成和复选框无法正常工作

我有一个包含不同类型字段的php表单(radio,checkbox,auto-complete,..)。 一切运作良好,直到我添加了jQueryvalidation插件来validation我的表单字段。

问题:自动完成字段不再起作用。 jQueryvalidation仍然适用于“无线电”类型,但不能使用复选框,它也会停用自动完成! 有人可以帮助我知道为什么会这样吗?

(因为整个代码很长,我只是粘贴自动完成部分+ jQuery表单validation)

Survey Questions

$(function() { //autocomplete $(".autofill").autocomplete({ source: "actorsauto.php", minLength: 3 }); }); $(function () { var scntDiv = $('#p_scents'); var i = $('#p_scents p').size() + 1; $('#addScnt').on('click', function (e) { e.preventDefault(); e.stopPropagation(); $('

').appendTo(scntDiv); $(function ($) { $('#p_scnt_' + i).autocomplete({ source: "actorsauto.php", minLength: 3 }); }); i++; // should increase counter here return false; }); $('.content-left').on('click', '.remScnt', function () { if (i > 2) { $(this).parents('p').remove(); i--; } return false; }); }); //other questions (tyoe: radio, checkbox,...) ..... $(document).ready(function() { $('#form2').validate({ // initialize the plugin errorLabelContainer: "#messageBox", wrapper: "li", rules: { q8[]: { required: true, }, q9[]: { required: true, }, q10: { required: true, }, q11: { required: true, } }, errorPlacement: function(error, element) { if (element.attr("type") == "radio") { error.insertBefore(element); } else { error.insertAfter(element); } } }); });

感谢David回答了这篇文章 ,我可以解决这个问题。 正如他所说:

无论什么版本,jquery库只应加载一次。 如果再次加载,则在最后一次添加之前添加的任何插件都将无法使用。

所以,我刚刚删除了

现在自动完成再次工作:)