mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Reworked the attribute selection code to be able to select false-y values - and added some tests to verify that they work well against expandos.
This commit is contained in:
parent
ab74ce7b57
commit
b16da9d762
@ -564,7 +564,16 @@ var Expr = Sizzle.selectors = {
|
|||||||
return match.test( elem.className );
|
return match.test( elem.className );
|
||||||
},
|
},
|
||||||
ATTR: function(elem, match){
|
ATTR: function(elem, match){
|
||||||
var result = Expr.attrHandle[ match[1] ] ? Expr.attrHandle[ match[1] ]( elem ) : elem[ match[1] ] || elem.getAttribute( match[1] ), value = result + "", type = match[2], check = match[4];
|
var name = match[1],
|
||||||
|
result = Expr.attrHandle[ name ] ?
|
||||||
|
Expr.attrHandle[ name ]( elem ) :
|
||||||
|
elem[ name ] != null ?
|
||||||
|
elem[ name ] :
|
||||||
|
elem.getAttribute( name ),
|
||||||
|
value = result + "",
|
||||||
|
type = match[2],
|
||||||
|
check = match[4];
|
||||||
|
|
||||||
return result == null ?
|
return result == null ?
|
||||||
type === "!=" :
|
type === "!=" :
|
||||||
type === "=" ?
|
type === "=" ?
|
||||||
@ -574,7 +583,7 @@ var Expr = Sizzle.selectors = {
|
|||||||
type === "~=" ?
|
type === "~=" ?
|
||||||
(" " + value + " ").indexOf(check) >= 0 :
|
(" " + value + " ").indexOf(check) >= 0 :
|
||||||
!check ?
|
!check ?
|
||||||
result :
|
value && result !== false :
|
||||||
type === "!=" ?
|
type === "!=" ?
|
||||||
value != check :
|
value != check :
|
||||||
type === "^=" ?
|
type === "^=" ?
|
||||||
|
@ -215,7 +215,7 @@ test("child and adjacent", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("attributes", function() {
|
test("attributes", function() {
|
||||||
expect(37);
|
expect(40);
|
||||||
t( "Attribute Exists", "a[title]", ["google"] );
|
t( "Attribute Exists", "a[title]", ["google"] );
|
||||||
t( "Attribute Exists", "*[title]", ["google"] );
|
t( "Attribute Exists", "*[title]", ["google"] );
|
||||||
t( "Attribute Exists", "[title]", ["google"] );
|
t( "Attribute Exists", "[title]", ["google"] );
|
||||||
@ -234,6 +234,13 @@ test("attributes", function() {
|
|||||||
t( "for Attribute", "form label[for]", ["label-for"] );
|
t( "for Attribute", "form label[for]", ["label-for"] );
|
||||||
t( "for Attribute in form", "#form [for=action]", ["label-for"] );
|
t( "for Attribute in form", "#form [for=action]", ["label-for"] );
|
||||||
|
|
||||||
|
jQuery("form input")[0].test = 0;
|
||||||
|
jQuery("form input")[1].test = 1;
|
||||||
|
|
||||||
|
t( "Expando attribute", "form input[test]", ["text1", "text2"] );
|
||||||
|
t( "Expando attribute value", "form input[test=0]", ["text1"] );
|
||||||
|
t( "Expando attribute value", "form input[test=1]", ["text2"] );
|
||||||
|
|
||||||
t( "Attribute containing []", "input[name^='foo[']", ["hidden2"] );
|
t( "Attribute containing []", "input[name^='foo[']", ["hidden2"] );
|
||||||
t( "Attribute containing []", "input[name^='foo[bar]']", ["hidden2"] );
|
t( "Attribute containing []", "input[name^='foo[bar]']", ["hidden2"] );
|
||||||
t( "Attribute containing []", "input[name*='[bar]']", ["hidden2"] );
|
t( "Attribute containing []", "input[name*='[bar]']", ["hidden2"] );
|
||||||
|
Loading…
Reference in New Issue
Block a user