【问题标题】:js Form Submit Button Not Workingjs表单提交按钮不起作用
【发布时间】:2014-04-15 02:09:04
【问题描述】:

代码如下,不确定我缺少什么或可能需要编辑什么。我对 JavaScript 比较陌生。请帮忙!我尝试添加“onClick”以及最终提交,以下代码(如在较大代码中标记的那样)是“联系提交”。我为我的平面设计作品集购买了这个网站 - 我可以在一定程度上阅读编码,但这个网站让我陷入了困境。

$("#submit_btn").click(function(){      
    var user_name=$('input[name=name]').val();
    var user_email=$('input[name=email]').val();
    var user_message=$('textarea[name=message]').val();
    var proceed=true;
        if(user_name==""){
            $('input[name=name]').css('border','2px solid #F54A4B');
            proceed=false
        }
        if(user_email==""){
            $('input[name=email]').css('border','2px solid #F54A4B');
            proceed=false
        }
        if(user_message==""){
            $('textarea[name=message]').css('border','2px solid #F54A4B');
            proceed=false
        }
        if(proceed){
            post_data={'userName':user_name,'userEmail':user_email,'userMessage':user_message};
            $.post('php/contact_me.php',
            post_data,
            function(data){
                $("#result").hide().html('<div class="success">'+data+'</div>').fadeIn(700);
                $('#contact_form input').val('');
                $('#contact_form textarea').val('')}).fail(
                function(err){
                    $("#result").hide().html('<div class="error">'+err.statusText+'</div>').fadeIn(1500)
            });
        }
});

$("#contact_form input, #contact_form textarea").keyup(function(){      
        $("#contact_form input, #contact_form textarea").css('border','2px solid #fff');
        $("#result").fadeOut(700)           
}); 

【问题讨论】:

  • 你的提交在哪里?
  • 不确定您在问什么?这是未更改的代码,从未正式提交。这可能是我的问题,哈哈。
  • 是的,这就是问题所在。
  • prntscr.com/3a3rm8 这是我放的地方,当我点击按钮时它仍然显示“错误”。

标签: javascript button submit contact-form


【解决方案1】:

要提交表单,您必须使用.submit() 函数。
使用$("#submit_btn").submit() 提交表单。
请通过https://api.jquery.com/submit/ 一次。

【讨论】:

  • 仍然出现“错误”,这是我插入代码的地方,与上面的 sn-p 相关(截图)prntscr.com/3a3rm8
  • 你必须在里面添加onclick函数。
  • 好的,我会试试这个。我也有 .PHP 编码中的联系表单/按钮的编码。这会带来更大的不同吗?
  • - 将“on”放入,点击按钮时,表单没有任何反应。
猜你喜欢
  • 2015-10-10
  • 2016-09-18
  • 2020-08-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多