用于简单菜单扩展的 Javascript
您好,我是 JavaScript 新手,我想编写一个非常简单的扩展子菜单。
<div id="submenu">
<ul>
<li>
Something
</li>
<li>
Another
</li>
</ul>
<div id="submenu-1" class="submenu-options">
<ul>
<li>Something-sub</li>
<li>Something-sub</li>
<li>Something-sub</li>
</ul>
</div>
<div id="submenu-2" class="submenu-options">
<ul>
<li>Another-sub</li>
<li>Another-sub</li>
<li>Another-sub</li>
</ul>
</div>
</div>
更具体地说,如果我将鼠标悬停在某物上,我希望显示某物子菜单,如果鼠标离开,我希望它再次隐藏...... 我知道这个问题已经被问了很多,并且有很多方法可以做到这一点,但谷歌提出了太多令人不满意的答案。 我希望您能抽出 10 分钟的时间来帮助我摆脱痛苦,
并向您致以问候,谢谢!
Hi I'm new to JavaScript and I want to code a very simple expanding submenu.
<div id="submenu">
<ul>
<li>
Something
</li>
<li>
Another
</li>
</ul>
<div id="submenu-1" class="submenu-options">
<ul>
<li>Something-sub</li>
<li>Something-sub</li>
<li>Something-sub</li>
</ul>
</div>
<div id="submenu-2" class="submenu-options">
<ul>
<li>Another-sub</li>
<li>Another-sub</li>
<li>Another-sub</li>
</ul>
</div>
</div>
To be more specific, if I hover over something I want the something submenu displayed if the mouse leaves I want it to be hidden again...
I know it has been asked a lot and there are many ways to do this but Google brought up too many unsatisfying answers.
I hope you can spare 10 minutes to help me out of my misery
Regards and thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您没有使用任何库,那么您需要像这样绑定它:
或者您可以使用某些具有 API 的 javascript 库轻松轻松地完成此操作。其中一些库是 Jquery(最流行的库) 、Sencha 等。
其中一些库具有具有菜单实现等的扩展。
if you are not using any library then you need to bind it something like this:
or you can do this nicely and easily using certain javascript libraries that have APIs to do this easily.. some of these libraries are Jquery (the most popular one), Sencha etc.
Some of these libraries have extensions that have menu implementation etc.
我已经使用 Dojo 来完成类似的事情并取得了巨大的成功。也许是 菜单 或 MenuBar 对您有用。
I have used Dojo for things like this with great success. Perhaps the Menu or MenuBar will be of use to you.
您可以使用 jQuery 轻松完成此类操作,以这个下拉示例为例:
HTML:
jQuery:
You can do this sort of thing easily with jQuery, take this drop down example:
HTML:
jQuery:
你不需要 java,因为只需简单的 CSS 即可:
You do not need java for this just plain CSS will do: