不同元素类型的name属性的jQuery选择器

我有一张桌子。 在其中一列中,某些行具有带静态文本的跨度,某些行具有可供选择的值的选择。 该列中的所有元素都具有相同的名称属性。 在我的表单提交中,我遍历行并想要获取所有列的值。 我更希望有一个jQuery选择器语句来获取该元素的值(span或select,name属性为“materialValue”)。 我怎么用jQuery做到这一点? 以下是html片段。

ONE
TWO
ONE TWO THREE
ONE TWO THREE

编辑:我习惯于指定元素类型,然后使用属性名称/值指定方括号。 我不知道如何在没有元素类型名称的情况下指定jquery选择器。 例如$('span[name="materialValue"]', this) 。 指定$('[name="materialValue"]', this)是合法的吗? 对我来说很奇怪。

您只需要一个属性选择器:

 $("[name='MaterialValue']") 

此外,您在html中的属性name后缺少结束引号

在此查看参考: http : //api.jquery.com/attribute-equals-selector/

像这样…

 $("[name=materialValue]") // Select element with name attribute with a specific value 

使用括号选择属性。 在其他情况下你也可以像这样使用它……

 $("div[id]") // Select element with an id attribute $("[name*=test]") // Select all elements with *test* in the name attribute (partial) 

等等..