【发布时间】:2019-05-02 08:11:07
【问题描述】:
升级 ACF 插件后,我的 onchange 函数 JS 文件在 wordpress function.php 上不再工作。我不知道它发生了什么事。 这是我的代码。你能启发我吗?
irevent_script.JS
(function($) {
$('#acf-field-acf_event_type').on('change', function () {
var selectVal = $("#acf-field-acf_event_type option:selected").val();
if(selectVal=="Others") {
$("#title").val("");
} else {
$("#title").val(selectVal);
}
});
})( jQuery );
In function.php
function irevent_script( $hook_suffix ){
$cpt = 'irevent';
if( in_array($hook_suffix, array('post.php', 'post-new.php') ) ){
$screen = get_current_screen();
if( is_object( $screen ) && $cpt == $screen->post_type ){
//wp_enqueue_script( 'tinymce_js', includes_url( 'js/tinymce/' ) . 'wp-tinymce.php', array( 'jquery' ), false, true );
wp_enqueue_script('irevent_js_script', get_bloginfo('template_url').'/js/irevent_script.js', array('jquery'), '4.7.5', true);
}
}
}
add_action( 'admin_enqueue_scripts', 'irevent_script');
【问题讨论】:
-
我不知道这是否会有所帮助。但最好将您的 wp_enque 上的完整 url 链接到您的脚本
-
@ScottChambers 感谢您的帮助。我注意到ACF升级后事件类型ID发生了变化。
标签: javascript jquery wordpress advanced-custom-fields