Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript HTML表单onsubmit错误/method=";邮政「;不起作用_Javascript_Php_Html_Forms_Submit - Fatal编程技术网

Javascript HTML表单onsubmit错误/method=";邮政「;不起作用

Javascript HTML表单onsubmit错误/method=";邮政「;不起作用,javascript,php,html,forms,submit,Javascript,Php,Html,Forms,Submit,我有一个可以正常工作的php/mysql表单提交,我试图在表单提交后禁用提交按钮 HTML <form action="" onsubmit="document.getElementById('submit-button').disabled = true;" method="post"> <p><label>Username</label> <input id="username" type="text" name="

我有一个可以正常工作的php/mysql表单提交,我试图在表单提交后禁用提交按钮

HTML

<form action=""  onsubmit="document.getElementById('submit-button').disabled = true;" method="post">
     <p><label>Username</label>
     <input id="username" type="text" name="username" value=""  autofocus/></p>

     <p><label>Password</label>
      <input type="password" name="password" value=""  /></p>

      <p><label></label>
     <input type="submit" id="submit-button" name="submit" value="Login"  /></p>
</form>

但是没有运气

而不是使用javascript。您可以直接使用php

<form action="" method="post">
<p><label>Username</label><input id="username" type="text" name="username" value=""  autofocus/></p>
<p><label>Password</label><input type="password" name="password" value=""  /></p>
<p><label></label><input type="submit" id="submit-button" name="submit" value="Login"  <?php  echo ('POST' == $_SERVER['REQUEST_METHOD']) ? 'disabled' : ''?>/></p>
</form>

用户名

密码

使用jquery

<form action="" method="post">
<p><label>Username</label><input id="username" type="text" name="username" value=""  autofocus/></p>
<p><label>Password</label><input type="password" name="password" value=""  /></p>
<p><label></label><input type="submit" id="submit-button" name="submit" value="Login"/></p>
</form>

您的表单似乎是直接提交的,执行“action”标记。如果您想保持相同的表单,请尝试使用AJAX请求

试试看:

<form action="" method="post">
     <p><label>Username</label>
     <input id="username" type="text" name="username" value=""  autofocus/></p>

     <p><label>Password</label>
     <input type="password" name="password" value=""  /></p>

     <p><label></label>
     <input type="submit" id="submit-button" name="submit" value="Login" /></p>
</form>

用户名

密码

使用以下脚本:

<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
    $("#submit-button").on("click", function(e){
        // For demo purpose
        e.preventDefault();
        document.getElementById("submit-button").disabled = true; 
    });
</script>

$(“#提交按钮”)。在(“单击”上,功能(e){
//用于演示目的
e、 预防默认值();
document.getElementById(“提交按钮”).disabled=true;
});

这个问题没有用jQuery标记,那么为什么要添加一个完整的库来阻止表单的默认操作呢?
<form action="" method="post">
     <p><label>Username</label>
     <input id="username" type="text" name="username" value=""  autofocus/></p>

     <p><label>Password</label>
     <input type="password" name="password" value=""  /></p>

     <p><label></label>
     <input type="submit" id="submit-button" name="submit" value="Login" /></p>
</form>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
    $("#submit-button").on("click", function(e){
        // For demo purpose
        e.preventDefault();
        document.getElementById("submit-button").disabled = true; 
    });
</script>