我有一个网站,使用联系表格7插件为我的联系表格 .
我添加了一个JQuery函数,它将在单击提交按钮之前聚焦第一个空字段 .
我想要做的是当我点击提交按钮时所有字段都是空的,我想要的是在点击提交按钮后聚焦第一个空字段 .
我应该使用什么JQuery函数?现在这是我的JS:
$( ".col-form3").find( "input:first").focus();
注意:在单击提交按钮之前,上面的jquery正确执行 .
你会这样做:
HTML:
<input type="text" name="t1" value=""> <input type="text" name="t2" value=""> <input type="text" name="t3" value=""> <input type="button" name="button" id="button" value="button">
$(document).ready(function(){$( “#键”) . 在( '点击',函数(){$( “输入:否(:复选框:按钮)”) . 每个(函数(){if(!$(this).val()){$(本).focus();返回false;}});});});
FIDDLE DEMO
下面的代码应该适合你:
$(".wpcf7-submit").click(function(){ $(".wpcf7-submit").ajaxComplete(function(){ if($(".wpcf7-response-output").hasClass("wpcf7-validation-errors")){ $(".wpcf7-form-control").each(function(){ if($(this).val().length === 0){ $(this).focus(); return false; } }); } }); });
如果您有任何疑问,请告诉我 .
试试这个java脚本代码:
<script type="text/javascript"> jQuery(document).ready(function($){ jQuery(".wpcf7-submit").ajaxComplete(function(){ var check = jQuery( ".wpcf7-form").find( ".wpcf7-not-valid:eq( 0 )"); if(check) { check.focus(); } }); }); </script>
3 回答
你会这样做:
HTML:
FIDDLE DEMO
下面的代码应该适合你:
如果您有任何疑问,请告诉我 .
试试这个java脚本代码: