简体   繁体   English

创建javascript菜单的最佳方法是什么?

[英]what is the best way to create javascript menu?

What is the best way or an easy way to create a javascript menu. 什么是创建javascript菜单的最佳方法或简便方法。 When I say best, I mean there are many softwares that help in creating menus, for eg. 最好的意思是,有很多软件可以帮助您创建菜单,例如。 Sothink DHTML menu. 硕思DHTML菜单。 Isnt there a menu control available in javascript? javascript中没有可用的菜单控件吗?

是您可以引用的JQuery炫酷菜单。无论如何,Javascript是客户端脚本语言,根本没有控制权。

There is no reason to buy or even just install a program solely for the purpose of constructing a JavaScript menu. 没有理由仅仅为了构建JavaScript菜单而购买甚至安装程序。

First of all, the menu itself should not contain any JavaScript code. 首先,菜单本身不应包含任何JavaScript代码。 It should just be a nested list. 它应该只是一个嵌套列表。 You shouldn't need a program to write that code for you. 您不需要程序来为您编写该代码。 If you do, then you're probably using a WYSIWYG editor anyways, and any WYSIWYG HTML editor will create an unordered list for you. 如果这样做,那么您可能仍在使用WYSIWYG编辑器,任何WYSIWYG HTML编辑器都会为您创建无序列表。

Once you've created the menu structure, you just need to add the display style and behavior to make it look/behave like a dropdown or flyout menu. 创建菜单结构后,只需添加显示样式和行为即可使其看起来/具有下拉菜单或弹出菜单的外观。 This can be done either in pure CSS or with CSS + JavaScript. 这可以在纯CSS或CSS + JavaScript中完成。 Some people prefer to use JavaScript to turn a regular list into a dropdown/flyout menu because they think using display: none is bad for SEO, and if you style items like that to begin with, then people without JavaScript will not be able to see the hidden menu items. 有些人更喜欢使用JavaScript将常规列表转换为下拉菜单/弹出菜单,因为他们认为使用display: none对SEO不利,如果您以此类开头的样式,那么没有JavaScript的人将无法看到隐藏的菜单项。 However, there are ways around both of those problems using pure CSS. 但是,使用纯CSS可以解决这两个问题。

If you're using jQuery, then there are a number of jQuery plugins that let you create your menus with just 1-2 lines of code. 如果您使用的是jQuery,那么有许多jQuery插件可让您仅用1-2行代码即可创建菜单。 Otherwise, there are standalone scripts and that can do the same. 否则,会有独立的脚本,并且可以执行相同的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM