php - 我如何通过 Wordpress 使用 jQuery UI?

标签 php javascript jquery wordpress

我正在尝试让 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/

相关文章:

javascript - jquery 选择所有不包含特定文本的行

php - curl 错误 : unable to set private key file: 'test.pem' type PEM

php - PDO:参数号无效:参数未定义。但是我有所有的领域?

php - 通过 Facebook Graph API 编辑评论

JavaScript 对象不会打印

javascript - Firebase - 推送数据

javascript - iFrame 关闭后重新加载父窗口

php - 似乎无法将 JSONObject 从 android 发送到远程服务器

JavaScript 滚动到底部不起作用

jquery - 切换标签后刷新页面