事件错误.预防默认
Errors with event.preventdefault
这不起作用
.JS:
var currentPath = window.location.pathname; var currentPage = currentPath.substring(currentPath.lastIndexOf('/') + 1); $(函数() { $("#shoutBox").submit(function(event) { event.preventDefault(); var 值 = $('#shoutBox').serialize(); $.post("shoutbox.php", values) .done(function(data) { $('input:text[name=shout]').val("JE SHOUT IS GEPOST!瓦赫特 1 米努特! $('input:text[name=shout]').attr('readonly', true); 设置超时( 函数() { $('input:text[name=shout]').val("JE KAN EEN NIEUWE SHOUT MAKEN!"); $('input:text[name=shout]').attr('readonly', false); }, 60000); }); }); }); $(函数() { $("#newName").submit(function(event) { event.preventDefault(); var valuen = $('#newName').serialize(); $.post("shoutbox.php", valuen) .done(function(data) { 重新加载(); }); }); }); 功能to_new_page(链接) { $("#content").fadeOut(function() { $(this).load(link+" #content", function() { $(this).fadeIn(); }) }); history.pushState({change: "page"}, "RandomRadio", "/"+link); } 函数重装() { to_new_page(当前页); }
表格 #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) {
相关文章:
- 在AngularJs中隐藏默认错误消息
- 具有默认参数值的 ES6 类构造函数上的 NodeJS 错误
- 如何在Ajax错误上抛出404错误,以便指向默认的404行为
- JayData 上的默认错误回调
- 如何用“重定向”来重定向网页;http错误404”;自动切换到默认网页
- jspm强制错误的默认值
- 通过在默认值中指定错误值来避免陷阱
- Javascript开关情况-导致错误的默认选项
- 如何只有在所有默认项都通过且没有错误后才能运行Gulp任务
- angular js中的默认错误处理程序
- DataTables:未捕获类型错误:无法读取属性'默认'的未定义
- jQuery promise的默认错误函数
- 骨干网默认错误获取功能
- 错误:github推送后未指定默认引擎,也未提供扩展
- Angular:未处理http错误的默认处理程序
- 在某些目录级别内的默认登陆页面出现404错误
- 如何获得ajax调用的默认错误
- Ember上的默认错误模板未加载
- 更改mootools表单验证器的默认错误消息
- 在具有相同名称的多个复选框上设置必需属性,并将默认错误消息替换为自定义