我有一个使用jQuery1.7的旧网站,直到两天前还可以正常运行.突然,我的一些按钮不起作用了,点击它们后,我在控制台上得到了以下警告:

表单深渊翻滚已取消,因为该表单未连接

The code behind the click is something like this:

 this.handleExcelExporter = function(href, cols) {
   var form = $('<form method="post"><input type="submit" /><input type="hidden" name="layout" /></form>').attr('action', href);
   $('input[name="layout"]', form).val(JSON.stringify(cols));
   $('input[type="submit"]', form).click();
 }

似乎Chrome56不再支持这种代码了.难到不是么?如果是,我的问题是:

  1. 为什么事情突然发生了?没有任何反对警告?
  2. What is the workaround for this code?
  3. 有没有办法在不更改任何代码的情况下强制Chrome(或其他浏览器)像以前一样工作?

P.S.个 它在最新的Firefox版本中也不起作用(没有任何消息).它也不能在IE 11.0&amp;Edge中工作!(两者均无任何信息)

推荐答案

Quick answer : append the form to the body.

document.body.appendChild(form);

或者,如果您使用如上所述的jQuery:$(document.body).append(form);

Details : According to the HTML standards, if the form is not associated to the browsing context(document), the form submission will be aborted.

HTML SPEC see 4.10.21.3.2

In Chrome 56, this spec was applied.

Chrome code diff请参阅@@-347,9+347,16@

关于你的问题#1.在我看来,与ajax不同,表单提交会导致页面即 timeshift 动

Jquery相关问答推荐

如何向父元素添加类?

jQuery .first() 方法返回第一个元素的集合

如何使用 jQuery 的 drop 事件上传从桌面拖动的文件?

使用 jQuery $.ajax() 时如何使用 GET 在请求正文中发送数据

如何确定 jQuery 中匹配元素的元素类型?

元素上的 jQuery Change 事件 - 有什么方法可以保留以前的值?

如何使用 jQuery 重置 jquery Select 的 Select 选项?

为什么 jquery fadeIn() 不能与 .html() 一起使用?

Ajax 更新后在 jQuery 中重新绑定事件(更新面板)

从 iframe 访问父窗口的元素

jQuery 判断 是否存在并且有一个值

在 HTML 表单提交上制作 Enter 键而不是激活按钮

如何使所有浏览器都支持 ?有什么 Select 吗?

jquery 从特定表单获取所有输入

将每 3 个 div 包装在一个 div 中

jQuery从字符串中删除'-'字符

Backbone.js - 事件,知道点击了什么

无法更新数据属性值

jQuery empty() 与 remove()

带有 LIKE 的 Spring JPA @Query