event.preventdefault发生错误
这不起作用
JS:
var currentPath = window.location.pathname;
var currentPage = currentPath.substring(currentPath.lastIndexOf('/') + 1);
$(function() {
$("#shoutBox").submit(function(event) {
event.preventDefault();
var values = $('#shoutBox').serialize();
$.post("shoutbox.php", values)
.done(function(data) {
$('input:text[name=shout]').val("JE SHOUT IS GEPOST! WACHT 1 MINUUT!");
$('input:text[name=shout]').attr('readonly', true);
setTimeout(
function()
{
$('input:text[name=shout]').val("JE KAN EEN NIEUWE SHOUT MAKEN!");
$('input:text[name=shout]').attr('readonly', false);
}, 60000);
});
});
});
$(function() {
$("#newName").submit(function(event) {
event.preventDefault();
var valuen = $('#newName').serialize();
$.post("shoutbox.php", valuen)
.done(function(data) {
reload();
});
});
});
function to_new_page(link)
{
$("#content").fadeOut(function()
{
$(this).load(link+" #content", function()
{
$(this).fadeIn();
})
});
history.pushState({change: "page"}, "RandomRadio", "/"+link);
}
function reload()
{
to_new_page(currentPage);
}
#shoutBox表单工作成功。
但是当我提交表单#newName两次时,它会刷新页面。
也许是因为你的.done调用reload() ?
尽管如此,我还是会加上return false;
$("#newName").submit(function(event) {
event.preventDefault();
var valuen = $('#newName').serialize();
$.post("shoutbox.php", valuen)
.done(function(data) {
reload();
});
return false;
});
请,修正你的报价。 选择单引号或双引号并坚持。
我有一个修复:)
我在我的提交按钮中添加了一个id并使用它
$("#submitshout").live("click", function(event){
代替
$("#shoutBox").submit(function(event) {
链接地址: http://www.djcxy.com/p/51957.html
