即时切换信息的下拉菜单
我想写一个 html 页面,上面有一个下拉菜单和一些内容。例如,一个下拉菜单列出了一周中的 7 天,并且根据选择的日期,div 包含了当天的活动。我知道如何完成这项工作,以便您可以选择所需的日期,按下按钮,然后浏览器会加载包含所需信息的新页面。我将如何编写它,以便一旦用户单击下拉菜单条目,页面的信息就会改变。我在想也许我可以将信息存储在一堆隐藏的 div 中,单击下拉菜单的条目后,可以将其换入和换出。但是,我不确定如何捕获选择下拉菜单中的条目的事件。
I am looking to write an html page that has a drop down menu on it and some content. For instance, a drop down menu that has the seven days of the week listed and depending which day is selected a div contains that day's activities. I know how to make this work so that you can pick the day you want, press a button, and then the browser loads a new page with the desired info. How would I go about writing it so that as soon as the user clicks on the drop down menu entry the page's info alters. I was thinking that maybe I could store the info in a bunch of hidden divs that, upon clicking on the drop down menu's entry, could be swapped in and out. I'm not sure, however, how to capture the event of an entry in a drop-down menu being selected.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还可以使用 AJAX 加载数据。
JavaScript 有很多事件: http://www.w3schools.com/jsref/dom_obj_event.asp
我使用 div 做了一个很糟糕的例子:
You can also use AJAX to load data.
JavaScript has lots of events: http://www.w3schools.com/jsref/dom_obj_event.asp
I've done poor example using divs:
如果您有这样的静态数据,我建议您使用 jQuery 来实现一些显示/隐藏技巧。
如果你看一下代码,你可以看到我加载 jQuery 来使用隐藏/显示等功能。
每次在下拉列表上触发更改时,div 中具有类:“hideAndShow”的所有 div 都会隐藏。之后,我显示已选择的 div 并检索所选值。
I would recommend you to use jQuery to achieve some show/hide tricks if you have static data like this.
If you take a look at the code, you can see I load jQuery to use function like, hide/show.
Everytime a change is triggered on the drop down list, all the div in the div with the class : "hideAndShow" are hidden. Right after that, I show the div that has been selected retrieving the selected value.