提交后,我想通过jQuery隐藏提交按钮。它会隐藏起来,但在页面重新加载后不久...为什么?
HTML:
<!DOCTYPE html>
<html>
<head>
<script src="js/submit_rsvp.js"></script>
<script src="js/jquery-1.2.3.pack.js"></script>
<script src="http://code.jquery.com/jquery-git.js"></script>
</head>
<body>
<form name="rsvp" method="post" action="" id='form'>
<input type='submit' name='submit' value='submit' id='submit' class='clickMe'>
</form>
</body>
</html>JS:
$(document).ready(function() {
$(".clickMe").click(function() {
$("submit").hide();
});
});谢谢!库尔顿
发布于 2011-04-28 05:54:08
您的表单操作为空。所以当你点击submit时,它只会使用当前页面作为操作。这就是它重新加载当前页面的原因。如果你不想让它提交表单,你可以这样做:
$("#form").submit(function(e) {
e.preventDefault();
$("submit").hide();
});发布于 2011-04-28 05:53:10
当你提交的时候,页面会重新加载,所有的事情都会重新开始。请尝试以下操作。
$(document).ready(function() {
$(".clickMe").click(function() {
$("submit").hide();
return false;
});
});发布于 2011-04-28 05:53:27
这是因为它是一个submit按钮,它会导致表单生成一个新的POST查询并重新加载页面。添加:
event.preventDefault();在匿名函数的开头重写此默认行为。
https://stackoverflow.com/questions/5811031
复制相似问题