jQuery 查找并提供值问题
代码位于:http://jsfiddle.net/m9yen/
问题:
- 我有多个 LI 的列表 食品
- 每个li 包含一个链接(添加),其中 href 是一个 rel,它保存特定的 FOODID
- 我现在需要一个数量输入框,
- 我还需要使用下拉菜单选择服务类型(即克等我将填充)
- 最终问题是单击添加时,我需要获取 href 的 rel、输入值和所选选项仅适用于该特定 LI 和通过ajax将其发送到request.php。
现在我确实让它专门与 rel 一起工作,只有正弦,如果单击 href 获取 attr('rel') 并通过 ajax 将其提交到 request.php - 但是因为这需要 href 之外的项目的其他值,但仅在那个特定的 LI 中,我迷路了,并尝试使用 .find() 但没有运气。
注意:将有多个列表,可能有 50-100 个列表(每个 LI)
Code is at: http://jsfiddle.net/m9yen/
Issue:
- I have multiple LI's listing FOOD ITEMS
- Each li contains a link (add) and in that href is a rel which holds that specific FOODID
- I now need to have an input box for QUANITY
- I also need to a select with dropdowns for SERVING TYPE (i.e. grams, et which I'll populate)
- End issue is when the add is clicked, I need to get the rel for the href, the value of the input and the selected option for that specific LI ONLY and sent it to request.php via ajax.
Now I did have it working specifically with the rel only sine it was a if href is clicked get attr('rel') and submit it via ajax to request.php -- BUT since this requires other values of items outside the href but only within that specific LI, I'm lost and have tried using .find() with no luck what so ever.
NOTE: There will be more than one, possible 50-100 listings (each LI)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于
input
和select
元素是其兄弟元素,因此您必须使用siblings
方法来查找它们。由于元素的名称与您要匹配的元素的名称相同,因此请使用=
而不是=^=
并仅使用"rel"
来获取来自锚点的属性值而不是“a#rel”。演示
Since
input
andselect
elements are its siblings you have to usesiblings
method to find them. Since the name of the elements are same as what you are matching use=
instead of=^=
and just use"rel"
to get the attribute value from anchor instead of"a#rel"
.Demo
http://jsfiddle.net/m9yen/3/ - 一般都整理好了。
#addING
的点击event.preventDefault()
(而不是return false
)以执行链接。 siblings()...val()
获取输入值的=^=
更改为=
- 无论如何,您都会匹配确切的名称。如果您需要“开头为”,只需^=
即可http://jsfiddle.net/m9yen/3/ - generally tidied up.
#addING
in shorter syntaxevent.preventDefault()
instead ofreturn false
to prevent link execution.siblings()...val()
to get values of inputs=^=
to just=
- you're matching the exact name anyway. If you need "starting with", just^=
will do