【发布时间】:2016-01-26 20:44:05
【问题描述】:
我正在使用完美运行的 onload 事件编辑 HTML 表单标签,
$(function (){
window.onload=function(){
var x = document.getElementsByTagName("form");
for (i = 0; i < x.length; i++) {
if(x[i].getAttribute("data-reactid") == ".0"){
x[i].id = "form1";
}
}
}
});
但是,当我尝试序列化表单 onbeforeunload 时,它为空,我做错了什么?我正在使用 chrome,我相信它不适用于其他浏览器。
$(function (){
window.onbeforeunload = function (e) {
var $k = $('#form1').serialize();
$.ajax({
type: "POST",
url: "MYURL",
data: { t: Date.now(), u: document.URL, k: $k}
});
};
});
HTML
<form class role="form" data-reactid=".0">
<input type="text" placeholder="Name" data-reactid=".0.1.0.1">
<input type="text" placeholder="Last Name" data-reactid=".0.1.0.1">
<button type="submit" data-reactid=".0.3">Submit</button></form>
谢谢! - 数字
【问题讨论】:
-
你能给我们一个关于jsfiddle的演示吗?
-
Stackoverflow 拥有 perfectly good way to provide live demos in questions 已经一年多了。无需将它们托管在 JS Fiddle 等第三方网站上。
标签: javascript jquery forms serialization javascriptserializer