我想将单击事件绑定到Wordpress自定义控件(主题定制程序)。我尝试过(customizer.js
):
$(document).on('click', '.element_class', function () {
console.log(5);
});
,但它并不束缚。
控件类似于:
Value
functions.php
:
function customizer_live_preview() {
wp_enqueue_script(
'theme-customizer',
get_stylesheet_directory_uri() . 'customizer.js',
array( 'customize-preview' ), '0.1.0', true);
}
add_action( 'customize_preview_init', 'customizer_live_preview' );
发布于 2019-01-10 22:29:18
您需要在具有不同依赖项的不同操作上对单独的脚本进行排队。
/**
* Enqueue styles and scripts for the Customizer pane.
*/
function mytheme_customize_pane_enqueue() {
wp_enqueue_script( 'mytheme-customizer-control',
get_template_directory_uri() . '/js/customizer-control.js',
array( 'customize-controls' ), '20180924', true );
}
add_action( 'customize_controls_enqueue_scripts', 'mytheme_customize_pane_enqueue' );
JS看起来如下:
( function( wp, $ ) {
wp.customize.control( 'mytheme_option', function( control ) {
control.container.on( 'click', '.element_class', function( event ) {
event.stopPropagation();
//control.doNotice( '' );
//control.applyPresetValues( $( this ).data( 'revert' ) );
} );
} );
} )( wp, jQuery );
https://wordpress.stackexchange.com/questions/317245
复制相似问题