【发布时间】:2012-01-12 13:33:55
【问题描述】:
我知道有可能,使用 jQuery,mix Multiple Selector with Multiple Attribute Selector,事实上,我使用了它。 例如,这很好用:
$('input[type="checkbox"][name^="selected"]:checked', theForm).length
在我的示例中,“theForm”是一个包含“#form1”的字符串,我用它来指代具有属性 id="form1" 的表单。
好吧,也就是说,问题是:是否可以将上述内容与 jQuery 过滤器混合使用? 这是一个代码示例:
var myVar = $('input[name^="modcc_"]', myForm).filter(...)
我尝试使用它,但我似乎没有在 myVar 中获取元素 但如果我以这种方式简单地删除“myForm”
var myVar = $('input[name^="modcc_"]').filter(...)
它有效...为什么?难道我做错了什么?我确定“myForm”变量已正确“填充”(它是一个包含“#formMod”的字符串,与我的表单的 id 属性一致)并且我确信输入在该表单内,并且它是唯一具有该 ID 的东西.
感谢您的帮助!
附: 这个问题来自one of my previous I made in a comment to the accepted answer to this question,没有得到回答。我认为无论如何都应该将其作为一个问题而不是简单的评论提出,所以......就是这样!希望有答案...
-编辑 按照要求,我将表单 HTML 代码放在这里:
<form action="..." method="post" id="formMod" name="formMod">
<input type="hidden" name="catid" value="412" />
<td width="8%">412</td>
<td>myName</td>
<td width="9%" style="white-space:nowrap; background-color:LightGoldenRodYellow;">
<input id="modcc_icv" name="modcc_icv" type="text" value="10" maxlength="3" size="4" />.
<input id="modcc_dcv" name="modcc_dcv" type="text" value="25" maxlength="2" size="3" />%
</td>
<td width="18%" class="actions_col" style="background-color:LightGoldenRodYellow;">
[ <a href="...">Annnulla</a> ]
<input type="submit" name="confirmMod" value="Salva" />
</td>
</form>
【问题讨论】:
-
这样的东西有帮助吗? $("#letters 选项").filter("[attr=a],[attr=b]").remove().或者你可以试试 .add() 类api.jquery.com/add
标签: jquery jquery-selectors filter attributes