我正在尝试让 jQuery UI 对话框与 WordPress 一起工作。我看到这篇文章(Using jQuery UI dialog in Wordpress)并尝试了解决方案,但它对我不起作用。以防万一,我使用的是基于二十一主题的子主题。
我把它直接放在 php 中的 wp_head() 函数前面:
function frontporch_enqueue_scripts() {
if (!is_admin() ) {
wp_enqueue_script( 'jquery' );
wp_register_script( 'google-jquery-ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js', array( 'jquery' ) );
wp_register_script( 'jquery-template', get_bloginfo('template_directory').'/js/jquery.template.js',array('jquery'),version_cache(), true);
wp_register_style( 'jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/smoothness/jquery-ui.css', true);
wp_enqueue_style( 'jquery-style' );
wp_enqueue_script( 'google-jquery-ui' );
wp_enqueue_script( 'jquery-template' );
}
}
add_action( 'init', 'frontporch_enqueue_scripts' );
我注意到 twentyeleven 主题或子主题实际上没有第三个脚本 (template.js),但我认为这不是导致问题的原因。
然后我在 HEAD 标签的底部添加了这个:
<script type="text/javascript">
$( "#markte_area" ).dialog({
autoOpen: false,
});
jQuery(document).ready(function($){
jQuery( "#markte_link" ).click(function() {
$( "#dialog" ).dialog( "open" );
return false;
});
}); //end document ready
</script>
我在加载页面时在错误控制台中收到以下错误:
Error: $ is not a function
发生这种情况的页面是 here如果这将帮助您诊断问题。感谢您的帮助!
最佳答案
在网络选项卡的 Firebug 中查看您包含的所有脚本,有时它是错误链接的 403 错误。 (顺便说一下,在检查之前清除所有缓存)。
jQuery 也能正常工作吗?
关于php - 我如何通过 Wordpress 使用 jQuery UI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11815668/