在插件中加载jQuery对话。
在管理排队脚本中排队
function enqueue_settings_scripts_styles($page) {
wp_enqueue_script ( \'my-plugin\', \'path/to/the.js\', array( \'jquery-ui-dialog\' ));
}
add_action(\'admin_enqueue_scripts\', enqueue_settings_scripts_styles\');
HTML<a style="cursor:pointer" class="cool-button">Click Me</a>
脚本(the.js
)(function($) {
console.log( "ready!" ); // this happens
var detailsButton = $(\'a.cool-button\');
console.log(detailsButton.click);
// this prints out to console:
// function (a,c){return arguments.length>0?this.on(b,null,a,c):this.trigger(b)}
detailsButton.click(function(e) {
alert(\'i happened\'); // never happens
e.preventDefault();
});
})(jQuery);
我花了一个多小时来解决这个问题。我错过了什么?