我有一个多页表格.
我想在此表单的最后一页上执行一些自定义JavaScript.从理论上讲,我所要做的就是检索当前页码并编写条件.
简单吧?显然不是.
我原来的解决方法是这样的:
if ($('gform_page').last().css('display') !== 'none') {
// perform custom scripts now that the last
// Gravity Form page is being shown
}
但是$(”’).css(‘display’)在我在表单中尝试过的每个元素上返回undefined.每次用户点击“下一步”按钮时,都会触发自定义脚本.没有雪茄.
然后,在回顾the Gravity Forms documentation之后,我发现了两个有用的事件:gform_post_render和gform_page_loaded.
但是,文档未提供有关如何访问参数的说明.
jQuery(document).bind('gform_page_loaded', function(event, form_id, current_page){
console.log(current_page);
// returns nothing when loaded in the footer
// returns [Object, object] when placed in an HTML field in the form
});
除了没有正确的代码之外,我还怀疑我没有正确的代码,因为我还在functions.php和header.php(as the documentation suggests)中尝试了以下内容:
function enqueue_custom_script($form, $is_ajax){
if ($is_ajax) :
echo '';
endif;
}
add_action("gform_enqueue_scripts", "enqueue_custom_script", 10, 2);
?>
题:
我需要什么代码来检索当前页码,更重要的是,我在哪里放置该代码?