【问题标题】:jQuery selectmenu wordpressjQuery 选择菜单 wordpress
【发布时间】:2019-01-16 17:29:52
【问题描述】:

我正在将一个网站从普通的 php 迁移到 wordpress,目前他们使用 jquery-selectmenu 插件作为他们的选择菜单。

我试图在 wordpress 头中将脚本排入队列,但没有成功。

上一个站点的脚本如下所示。

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
<link rel="stylesheet" href="<?php echo $siteurl; ?>css/custom-theme/jquery-ui-1.8.1.custom.css" type="text/css" /> 
<script type="text/javascript" src="<?php echo $siteurl; ?>js/select-menu.js"></script>
<script type="text/javascript" src="<?php echo $siteurl; ?>js/init.js"></script>

init.js 只需调用函数即可工作

$(function(){
    $('select#speedC').selectmenu({style:'dropdown'});
});

现在在 Wordpress 中,我在脑海中添加了以下内容。

<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'template_url' ); ?>/custom-theme/jquery-ui-1.8.1.custom.css" />
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />

<?php wp_enqueue_script( 'jquery-ui-core' ); ?>
<?php wp_enqueue_script( 'swfobject' ); ?>
<?php wp_enqueue_script( 'ui-core-select', get_bloginfo('template_directory') . '/js/select-menu.js' ); ?>
<?php wp_enqueue_script( 'jquery-pajinate', get_bloginfo('template_directory') . '/js/jquery.pajinate.js' ); ?>
<?php wp_enqueue_script( 'jquery-ui', get_bloginfo('template_directory') . '/js/jquery-ui.1.7.2.min.js' ); ?>

还有我页面中的脚本

<script type="text/javascript">
    $j=jQuery.noConflict();

    // Use jQuery via $j(...)
    $j(document).ready(function(){
        $j('select#speedC').selectmenu({style:'dropdown'});
    });
</script>

任何想法为什么它没有启动?

【问题讨论】:

    标签: wordpress jquery-ui jquery-plugins wordpress-theming


    【解决方案1】:

    我知道这是一个老问题,但添加它是因为它在 Google 中的排名很高,可能对其他人有所帮助。

    大多数 jQuery UI 组件都包含在 WordPress 中,但默认情况下不入队,您需要将它们入队。

        wp_enqueue_script( 'jquery-ui-selectmenu' );
    

    http://jafty.com/blog/tag/how-to-use-jquery-ui-in-wordpress/ 有一个有用的包含组件和入队字符串的列表

    【讨论】:

    • 救了我的培根。谢谢。
    【解决方案2】:

    在做了更多研究之后,我发现现有的库目前没有保持最新状态,并且不能很好地与 jQuery 配合使用。

    从现在开始参考这个jQuery.ui.selectmenu.js

    【讨论】:

    • 请注意即将发布正式版:github.com/jquery/jquery-ui/tree/selectmenu
    • Wordpress 中的jquery-ui-selectmenu 目前是1.11.4,是较新的版本。它在 Wordpress 中出现故障一定有其他原因。您链接的那个已经有几年没有更新了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-16
    • 1970-01-01
    • 2012-02-14
    • 1970-01-01
    相关资源
    最近更新 更多