表行的 jQuery 下拉菜单
我在当前的项目中遇到了一些困难,希望有人可以帮助我澄清事情。
我有一个表,我需要根据给定的行执行操作,第一个 td 中有一个 jQueryUI 按钮,该按钮应该下拉一个包含该行功能的菜单。每个 tr 都有用于标识人和项目的值,但我不知道如何动态创建下拉列表来处理该行的特定项目。
例如,我的 tr 如下所示:
<tr person="1" item="1"><td class="ddmenu">Row1</td>...</tr>
<tr person="2" item="5"><td class="ddmenu">Row2</td>...</tr>
我的 jQuery 函数,它查找该行的人员和项目 id,并下拉菜单:
$('.ddmenu')
.click(function() {
var person = $(this).parents("tr").attr('person');
var item = $(this).parents("tr").attr('item');
$('.drop').toggle();
return false;
})
我有一个初始项目,其中列出了每行的相同项目,但有以下两个问题:
- 如何使用人员和项目值创建动态下拉菜单,以便我可以使用单独的 jQuery 选择器对每个项目进行操作。
- 如何将菜单直接放在特定按钮下方,而不是放在 html 中 div 的位置?
jsfiddle 示例: http://jsfiddle.net/CHrkd/3/
任何想法和澄清都会非常有用赞赏!谢谢
I'm struggling a little with my current project, and hope someone can help clarify things for me.
I have a table where I need to perform actions based on a given row, with a jQueryUI button in the first td, which should drop down a menu with functions for the row. Each tr has values to identify both the person and item, but I don't know how to dynamically create the dropdown to handle the specific items of the row.
For example, my tr looks like this:
<tr person="1" item="1"><td class="ddmenu">Row1</td>...</tr>
<tr person="2" item="5"><td class="ddmenu">Row2</td>...</tr>
My jQuery functions, which locate the person and item ids for the row, and drops down the menu:
$('.ddmenu')
.click(function() {
var person = $(this).parents("tr").attr('person');
var item = $(this).parents("tr").attr('item');
$('.drop').toggle();
return false;
})
I have an intial item that lists the same items for each row, but have the following two problems:
- How do I create the dynamic dropdown menu with the person and item values, so I can act upon each item with separate jQuery selectors.
- How can I drop the menu directly below the specific button, rather than the location of the div in the html?
jsfiddle example: http://jsfiddle.net/CHrkd/3/
Any thoughts and clarification will be greatly appreciated! Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我意识到我问了两个不相关的问题,并想回答第一个问题。最简单的方法是简单地使用全局变量。一旦“ddmenu”选择器触发,将人员和项目值保存到全局变量中以供进一步处理。简单易行。
现在,如果我能弄清楚如何将 .drop 类移动到单击的项目下。
I realized that I asked two unrelated questions, and want to answer the first. The easy method is to simply use global variables. Once the 'ddmenu' selector fires, save the person and item values to global variables for further processing. Easy peasy.
Now, if I can just figure out how to move the .drop class to line-up under the clicked item.