我正在尝试制作一个小部件插件,允许用户上传图像。但是我在jQuery事件中遇到了一个问题,那就是它永远不会发生!
includes/myplugin.scripts
function media_uploader_enqueue() {
wp_enqueue_media();
wp_register_script(\'media-uploader\', plugins_url().\'/simple-plugin/js/main.js\',array(\'jquery\'),null, true);
wp_enqueue_script(\'media-uploader\');
}
add_action(\'admin_enqueue_scripts\', \'media_uploader_enqueue\');
js/main.js
jQuery(document).ready(function ($) {
console.log($(\'#xyz\')); // works !
$(\'#xyz\').click(function (e) {
e.preventDefault();
console.log("in click event"); // never happens !!
})
})