我有以下无法更改的内联代码是由外国人插件输出的。包含onclick
触发submit
事件的处理程序:
<input type='button' id='gform_next_button_12_188'
class='button gform_next_button' value='Next' tabindex='3'
onclick='jQuery("#gform_target_page_number_12").val("2"); jQuery("#gform_12").trigger("submit",[true]); '/>
我想在提交表单之前运行一些例程,我尝试了这个:
$("#gform_12").submit(function(e){
// this code is not running ...
});
它失败了,即提交表单时我的代码没有运行。有什么建议吗?
基于给出的答案的最终解决方案
var inline_onclick_code_on_next = $(".gform_next_button").first().attr("onclick");
$(".gform_next_button").removeAttr("onclick");
$(".gform_next_button").bind("click", function() {
myClass.autosave_on_click(inline_onclick_code_on_next);
});
myClass = {
errorMessage : "",
autosave_on_click: function (inline_onclick_code){
my_gravity_form_saving_running = 1;
myClass.saveData(); // this code must put my_gravity_form_saving_running = 0 when all data be saved
countdown_max_loop = 10; // seconds
var countdown = window.setInterval(function(){
if (countdown_max_loop-- == 0 || my_gravity_form_saving_running == 0){
clearInterval(countdown);
eval (inline_onclick_code);
}
}, 1000);
}
}