【发布时间】:2012-08-02 16:18:35
【问题描述】:
我正在尝试让 jQuery UI 对话框与 WordPress 一起使用。我看到了这篇文章(Using jQuery UI dialog in Wordpress),我尝试了解决方案,但它对我不起作用。以防万一,我使用的是基于 211 主题的子主题。
我把这个直接放在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' );
我注意到 211 主题或子主题实际上没有第三个脚本(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>
我在加载页面时在错误控制台中收到以下错误:
错误:$ 不是函数
发生这种情况的页面是here,如果这有助于您诊断问题。感谢您的帮助!
【问题讨论】:
-
把$改成jQuery然后告诉我会发生什么?
-
我把它改成了 jQuery,现在它说“jQuery("#markte_area").dialog is not a function”
-
听起来 jQuery 没有加载。 Firebug 将帮助诊断正在发生的事情。
标签: php javascript jquery wordpress