您可以通过一点jQuery来实现这一点:
在文件夹/js/called字段clear中创建此文件。js和替换#formID
使用要重置的表单ID:
//Code runs when an ajax request succeeds
jQuery( document ).ajaxSuccess(function( event, xhr, settings ) {
//Check ajax action of request that succeeded
if(settings.action == \'add_tag\') {
//Reset the form
jQuery(\'#formID\')[0].reset();
//Send ajax response to console.
console.log("Triggered ajaxSuccess handler. The ajax response was: " + xhr.responseText );
}
});
然后在函数中。php加载javascript:
wp_register_script(\'field-clear-script\', get_stylesheet_directory_uri() . \'/js/field-clear.js\', array(\'jquery\'), null, true);
function field_clear_load_scripts() {
wp_enqueue_script(\'field-clear-script\');
}
add_action(\'admin_enqueue_scripts\', \'field_clear_load_scripts\');
编辑-添加代码以显示ajax响应文本。添加了对ajax操作参数的检查。将enqueue函数更改为在admin上排队,因为我认为这是必需的。