繁体   English   中英

JQuery 不会运行提交表单

[英]JQuery will not run to submit form

我可能错过了一些简单的东西。 此页面上的 JQuery 未运行。 这很明显,因为警报不会执行。 我只是想在不刷新页面的情况下提交表单。 另外,我没有收到控制台错误。 提前致谢。

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
    $(document).ready(function(e) {
       $('submitpicks').on('submit','#submitpicks',function(e){
            e.preventDefault();  //this will prevent reloading page
            alert('Form submitted Without Reloading');
       });
    });

</script>
</head>

<body>
<form name="submitpicks" id="submitpicks" action="" method="post">
<script type="">
var v=0;
function acceptpick(thepick,removepick){
    var userPick = confirm("You picked " + thepick + ". Accept this pick?");
    //var theid = "finalpick" + v;
    var removebtn = "btn" + removepick;
    //alert(theid);
    if(userPick==1){
        document.getElementById("finalpick").value=removepick;
        document.getElementById(removebtn).disabled = true;
        document.getElementById("submitpicks").submit();
        v=v+1;
    }
}
</script>
<?php
include "Connections/myconn.php";
//$setid = $_SESSION["gbsid"];
$setid = 11;
$setqry = "Select * from grabBagParticipants where gbsid = $setid order by rand()";
$setresult = mysqli_query($conn, $setqry);
$u=0;
if(mysqli_num_rows($setresult)>0){
    while($setrow = mysqli_fetch_array($setresult)){
        //shuffle($setrow);
        echo '<input type="button" name="' . $setrow["gbpid"] . '" id="btn' . $setrow["gbpid"] . '" value="' . $u . '" onClick=\'acceptpick("' . $setrow["gbpname"] . '", ' . $setrow["gbpid"] . ');\' /><br />';
        $u=$u+1;
    }
}
?>
<input type="text" name="finalpick" id="finalpick" />
<input type="submit" value="Save" />
</form>
<div id="results">&nbsp;</div>
</body>
</html>
   <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
    $(document).ready(function(e) {
       $('#submitpicks').on('submit',function(e){
            e.preventDefault();  //this will prevent reloading page
            alert('Form submitted Without Reloading');
       });
    });

</script>
</head>

<body>
<form name="submitpicks" id="submitpicks" action="test.php" method="post">
<script type="">
var v=0;
function acceptpick(thepick,removepick){
    var userPick = confirm("You picked " + thepick + ". Accept this pick?");
    //var theid = "finalpick" + v;
    var removebtn = "btn" + removepick;
    //alert(theid);
    if(userPick==1){
        document.getElementById("finalpick").value=removepick;
        document.getElementById(removebtn).disabled = true;
        document.getElementById("submitpicks").submit();
        v=v+1;
    }
}
</script>
<input type="text" name="finalpick" id="finalpick" />
<input type="submit" value="Save" />
</form>
<div id="results">&nbsp;</div>
</body>
</html>

这应该可以解决您的问题。 仅供参考,考虑到没有出现错误,只是在这里做 JS 对你不起作用。

 <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script> $(document).ready(function(e) { $('#submitpicks').submit(function(e) { e.preventDefault(); alert('Form Submitted without reloading.'); }) }); </script> </head> <body> <form name="submitpicks" id="submitpicks" action="" method="post"> <input type="text" name="finalpick" id="finalpick" /> <input type="submit" value="Save" /> </form> </body>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM