我如何打破jQuery .submit()循环

时间:2016-10-11 11:11:59

标签: javascript jquery html

我想要完成的是检查天气是否在我的申请中应用了优惠券代码,并提交表格以应用优惠券(如果尚未应用)。但是,控制台日志继续报告null并且不提交表单。

if(document.getElementById("#vapsummarycolcoupon").innerHTML== null) {
      $( "#activatecoupon" ).submit();
    } else {
      return null;
    }
}

当提交表单时,页面将重新加载并具有id =“vapsummarycolcoupon”的新元素,以便从页面中断不断提交我试图检查innerHTML!=“$ 5.00”以及= =“undefined”和== null但没有运气。某些事情必定是错误的,或者有更好的方法来完成这项任务。提前谢谢。

3 个答案:

答案 0 :(得分:1)

通过反转if语句,我实际上能够解决问题并检查长度。感谢你们尝试了一些人,因为你们无法解决这个问题,因此很难过。

$( window ).load(function() {
 if($("#vapsummarycolcoupon").length > 0 ) {
return null;
} else{
 $( "#activatecoupon" ).submit();
}
});

答案 1 :(得分:0)

试试这个,

if (typeof(Storage) !== "undefined") 
{
    alert("Browser doesn't support Storage");
} 
else 
{
    var X = document.getElementById("#vapsummarycolcoupon").innerHTML;
    if(X == "") 
    {
        if(sessionStorage.getItem("submit") != true)
        {
            sessionStorage.setItem("submit", true);
            $( "#activatecoupon" ).submit();
        }
        else
        {
            console.log("Already Submitted");
        }
    }
    else
    {
        return null;
    }  
}

答案 2 :(得分:0)

尝试:

if($("#vapsummarycolcoupon").innerHTML== null) {
  $( "#activatecoupon" ).submit();
} else {
  return null;
}