jQuery 选择菜单 WordPress
我正在将一个网站从普通的 php 迁移到 WordPress,目前他们使用 jquery-selectmenu 插件来选择菜单。
我尝试将脚本放入 WordPress Head 中,但没有成功。
上一个站点的脚本如下所示。
<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>
有什么想法为什么它没有启动吗?
I am moving a site from normal php to wordpress and currently they use jquery-selectmenu plugin for their select menus.
I have tried to enqueu the script in wordpress head with no luck.
The scripts from the previous site look as follows.
<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 simply calls the function and works
$(function(){
$('select#speedC').selectmenu({style:'dropdown'});
});
Now in Wordpress i added the following to my head.
<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' ); ?>
And the script in my page
<script type="text/javascript">
$j=jQuery.noConflict();
// Use jQuery via $j(...)
$j(document).ready(function(){
$j('select#speedC').selectmenu({style:'dropdown'});
});
</script>
Any ideas why it is not initiating?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道这是一个老问题,但添加这个问题是因为它在谷歌中出现得很高,可能会帮助其他人。
大多数 jQuery UI 组件都包含在 WordPress 中,但默认情况下不会排队,您需要用它来将它们排队。
http://jafty.com/blog/tag/how-to-use-jquery-ui-in-wordpress/
I know this is an old question but adding this as it appears high up in Google and may help others.
Most of the jQuery UI components are included with WordPress but are not enqueued by default, you need to enqueue them with this.
There's a helpful list of the included components and the enqueue string at http://jafty.com/blog/tag/how-to-use-jquery-ui-in-wordpress/
在做了更多研究后,我发现现有的库目前没有保持最新状态,并且不能很好地与 jQuery 配合。
从现在开始参考这个 jQuery.ui.selectmenu.js
After doing some more research I found that the existing library is not currently kept up to date and not playing well with jQuery.
From now on refer to this one jQuery.ui.selectmenu.js