ICode9

精准搜索请尝试: 精确搜索
首页?>?bet356体育下载> 文章详细

javascript – 表单提交导致’超出最大调用堆栈大小’

2019-09-30 10:35:44??阅读:8??来源: 互联网

标签:html?javascript?jquery?forms


bet356体育下载我创建了一个用于审查网站上某个人的表单,但是当提交表单时没有任何反应,控制台显示“超出最大调用堆栈”.希望有人可以帮助指出我的代码中的错误,阻止它工作.这是表单代码:

 

这是JS代码:

/* intercept submit event */
$( "#fReviewMe" ).submit(function(event) {
   checkForm();
   event.preventDefault();
});

/* form validation */
function checkForm(){

  var errors = 0;
  var cuname = $('#uname').val();
  var ccompany = $('#business').val()
  var creview = $('#reviewmsg').val()
  var cstars = $('#rStar').val()
  var eMessage = "";
  $('#dFormErrors').hide();
  $('input').removeClass('validFalse');
  $('textarea').removeClass('validFalse');

if ($('#tnc').is(':checked')) {
 }
 else{
    eMessage = "Please tick to accepts out terms and conditions";
    errors++;   
}

if(cstars.length < 1){
  $("input").blur();
  $("textarea").blur();
  eMessage = "Please choose a star rating";
  errors++;
}

if(creview.length < 1){
  $('#reviewmsg').focus();
  $('#reviewmsg').addClass('validFalse');
  eMessage = "Please add your review";
  errors++;
}
else{
  $('#reviewmsg').addClass('validTrue');
}

if(ccompany.length < 1){
  $('#business').focus();
  $('#business').addClass('validFalse');
  eMessage = "Please tell us your business name";
  errors++;
}
else{
  $('#business').addClass('validTrue');
}

if(cuname.length < 1){
  $('#uname').focus();
  $('#uname').addClass('validFalse');
  eMessage = "Please tell us your name";
  errors++;
}
else{
   $('#uname').addClass('validTrue');
}

/* check errors and submit */
if(errors > 0){
  $('#dFormErrors').slideDown();
  $('#sEMessage').html(eMessage)
}
else{
  $('#dButtonsReviewForm').hide();
  $('#dSavingReviewForm').show();
  $('#fReviewMe').submit();
}

};

提前致谢

解决方法:

替换$(‘#fReviewMe’).submit();有:

$('#fReviewMe')[0].submit();

调用DOM节点方法提交以避免提交jQuery处理程序’loop’.



标签:html,javascript,jquery,forms

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有