属性不被jQuery的属性选择器发现 [英] attributes not found by jquery attribute selector

查看:150
本文介绍了属性不被jQuery的属性选择器发现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要<一个href=\"http://stackoverflow.com/questions/742964/attributes-not-selectable-by-jquery-attribute-selector\">reask我的老问题,我可能不应该问它在凌晨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]");

到目前为止,似乎我不能使用表单的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]");

您将无法选择形式。没有什么特别的操作属性。这同样适用于徽标图像的网页上的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"/>

不工作的选择是:

The selector which does not work is:

$("img[src=/p/aost/logo?logo_id=1238551994");

当然,我可以做通配符匹配,这是不是我了。

Sure, i can do wildcard matches, that is not what i am after.

推荐答案

有没有不支持的属性列表,因为不应该有;这是jQuery的一个bug。

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:

  • 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

显然臭虫之间的共同点是,jQuery是比较指定打击,而不是实际的动作/ src属性,因为它是在HTML中定义的完整URL选择字符串。这就解释了为什么 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.

我会建议只是给表格/图像类/ ID和越来越过来。

I would recommend just giving the form/image a class/ID and getting it over with.

这篇关于属性不被jQuery的属性选择器发现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆