多个表单提交被阻止,但形式不通过

时间:2017-05-23 14:10:12

标签: javascript php jquery forms button

PHP

<?php
    echo '<form method="POST" action="" onsubmit="return checkForm(this);">
          <input type="submit" class="test1" name="myButton" value="Submit">
          <input type="submit" class="test1" name="myButton" value="Submit">
          <input type="submit" class="test1" name="myButton" value="Submit">
          </form>';

    if (isset($_POST['myButton'])) {echo 'Hey!';}
?>

的Javascript

<script type="text/javascript">

function checkForm(form) // Submit button clicked
{
    var elems = document.getElementsByClassName("test1");
    for(var i = 0; i < elems.length; i++) {
        elems[i].disabled = true;
    }
}
</script>

上面的脚本允许我在表单提交时禁用所有3个按钮,以防止在页面刷新之前多次提交。但是,表单提交没有通过(即'嘿'没有被回应)

有解决方法吗?

0 个答案:

没有答案