jquery属性选择器找不到属性 [英] attributes not found by jquery attribute selector
问题描述
我需要重写我的旧问题,我可能不应该已在上午1时询问:P
I need to reask my old question, I probably shouldnt have asked it at 1am :P
似乎使用jquery的属性选择器找不到某些属性:
It seems that some attributes are not being found using jquery's attribute selector:
$("*[some=value]");
到目前为止,我似乎不能使用form的action属性和img的src属性。是否有一个列表的某些属性不工作,所以我可以为他们编写自定义选择器?
So far it seems that i cant use form's action attribute, and img's src attribute. Is there a list somewhere of attributes that do not work so i can write custom selectors for them?
再次感谢!
编辑:
没有人相信一些选择器不能按预期工作。看看这个例子:
在这个网站(其上有jquery 1.3的firebugging )有一个如下形式:
No one seems to believe that some selectors do not work as expected. Look at this example: On this site (which has jquery 1.3 on it for firebugging) there is a form that looks like this:
<form style="display: inline;" method="get" action="list">
(在搜索当前下载内容下拉菜单中)。如果您打开firebug并尝试此选择器:
(its around the 'search current downloads' dropdown). If you open firebug and try this selector:
$("form[action=list]");
您将无法选择表单。 action属性没有什么特别的。此网页上标志图片的src也是如此:
you will NOT be able to select the form. There is nothing special about the action attribute. Same goes for the src of the logo image on that page:
<img alt="Logo" src="/p/aost/logo?logo_id=1238551994"/>
不起作用的选择器是:
$("img[src=/p/aost/logo?logo_id=1238551994");
当然,我可以做通配符匹配,这不是我之后。
Sure, i can do wildcard matches, that is not what i am after.
推荐答案
没有不支持的属性的列表,因为不应该有;这是jQuery中的一个错误。
There is no "list" of unsupported attributes because there shouldn't be; this is a bug in jQuery.
以下是关于此的公开票:
Here are the open tickets on this:
- 无法使用操作属性选择表单
- attractionof form and Selectors'attribute filter
- selector by attributesrc与1.2.6中的工作方式不同
- Can not select a form using the action attribute
- attr "action" of form and Selectors' attribute filter
- selector by attribute "src" not working the same way as in 1.2.6
显然,bug之间的共同点是jQuery比较你指定的选择器字符串和完整的URL,而不是实际的action / src属性在HTML中。这说明了为什么 attributeEndsWith 或 attributeContains 选择器在这种情况下工作。
Apparently the common denominator between the bugs is that jQuery is comparing the selector string you specify against the full URL as opposed to the actual action/src attribute as it is defined in the HTML. This explains why the attributeEndsWith or the attributeContains selectors do work in this case.
我建议只是给form / image一个类/ ID,并结束。
I would recommend just giving the form/image a class/ID and getting it over with.
这篇关于jquery属性选择器找不到属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!