我希望能在提交 Facebook 表单之前加密文本框中的文本。我尝试使用 beforeSerialize 或 beforeSubmit 的 ajaxFORM 插件进行加密,但加密并没有发生。在下面的代码中,为了调试目的,加密函数被替换为 alert。警报在运行脚本后立即出现,而不是在按下 Facebook 提交按钮时出现。此外,当我按下提交按钮时,它会要求刷新页面,我不想这样做。
var s = document.createElement('script');
s.setAttribute('src', 'http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js');
document.body.appendChild(s);
var f = document.createElement('script');
f.setAttribute('src', 'http://malsup.github.com/jquery.form.js');
document.body.appendChild(f);
var c = document.createElement('script');
c.setAttribute('src', 'http://malsup.github.com/chili-1.7.pack.js');
document.body.appendChild(c);
s.onload=function(){
$(document).ready(function() {
// bind form using ajaxForm
$(document.activeElement).closest("form").ajaxForm( {
beforeSerialize: alert($(document.activeElement).val()) } );
});
};