表单元素的 jQuery 选择器
我正在尝试确定此表单元素的选择器:
<form action="/php/edit_images_reorder.htm" method="post" name="draglist_form">
<input type="hidden" name="new_order" value="abc" />
...
这就是我现在正在处理的内容:
$("form > [name='new_order']").val(...)
我想从函数中为该表单元素分配一个值。有人知道正确的选择器是什么吗?谢谢!
I'm trying to determine the selector for this form element:
<form action="/php/edit_images_reorder.htm" method="post" name="draglist_form">
<input type="hidden" name="new_order" value="abc" />
...
This is what I'm working with right now:
$("form > [name='new_order']").val(...)
I want to assign a value to this form element from a function. Anyone know what the correct selector is? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我刚刚测试过它并且它有效: http://jsfiddle.net/H2D8x/1/
问候。
I've just tested it and it works: http://jsfiddle.net/H2D8x/1/
Regards.
这就是正确的选择器。过短。
That's the correct selector. Too short.
您走在正确的轨道上:
您的代码中哪些内容不起作用?
You were on the right track:
What wasn't working in your code?
试试
或者你可以给它一个 id 吗?更简单、更高效。
华泰
try
Or you could give it an id? easier and more performant.
HTH
我会同意
但是你拥有的应该没问题。
I'd go with
But what you have should be fine.
你的实际问题是什么?选择器对我来说似乎是正确的:
请参阅 http://jsfiddle.net/AP8VA/1/
我会请注意,为了保持一致性,您应该以相反的方式使用引号 - 使用双引号来表示属性,使用单引号来划分 Javascript 字符串。
这更适合 HTML,严格来说,属性应该用双引号引起来。
What's your actual problem? The selector appears correct to me:
See http://jsfiddle.net/AP8VA/1/
I would note for consistency that you should have the quote marks the other way around - use double quotes to represent the attribute and single quotes to demarcate the Javascript string.
This is a better fit for HTML which strictly speaking should have double quotes around attributes.