[英]Make an onClick Function for wordrpress custom menu item
I have a div on my wordpress site that I would like toggle (slideup/slide down) using one of the menu items in the navbar. 我在wordpress网站上有一个div,我想使用导航栏中的菜单项之一进行切换(向上滑动/向下滑动)。 The menu item is of type custom. 菜单项的类型为custom。 In the URL text field I have a hash tag. 在URL文本字段中,我有一个井号标记。
Does anyone know a plugin or any other method to make this work. 有谁知道一个插件或任何其他方法可以使这项工作。 I searched google but all I could find was this plugin http://wordpress.org/plugins/jin-menu/ . 我搜索了google,但我唯一能找到的就是这个插件http://wordpress.org/plugins/jin-menu/ 。 Its description is perfect for the job but completely fails when I upload and try to use it. 它的描述非常适合这项工作,但是当我上传并尝试使用它时完全失败。
According to Jin Menu documentation you can put a function into the Menu Option field. 根据Jin Menu文档,您可以将功能放入Menu Option字段。
With that said and the assumption you have Jquery already installed add this to your template. 这样说来,并假设您已经安装了Jquery,就可以将其添加到模板中。
<script>
jQuery(document).ready(function() {
jQuery('#idOfYourDiv').hide();
});
function toggleCollaspe() {
jQuery('#idOfYourDiv').slideToggle('slow');
}
</script>
add toggleCollaspe()
to your Menu Option 将toggleCollaspe()
添加到菜单选项
EDIT 编辑
after following the url i found the error to be on this line 跟随URL后,我发现此行上的错误
$('#headerStyleType').html()
is should be 应该是
jQuery('#headerStyleType').html()
There are other such errors in the code too 代码中也存在其他此类错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.