一个针对jQuery属性选择器的小例子,增加对jQUery属性选择器的理解: 复制代码 代码如下: <BR>a{ <BR>margin-right:20px; <BR>} <BR>ol{ <BR>position:relative; <BR>width:600px; <BR>margin-left:400px; <BR>} <BR>dt{ <BR>margin:10px; <BR>height:100px; <BR>background-color:#EAEAEA; <BR>border:3px dotted orange; <BR>} <BR>.showMessage{ <BR>width:380px; <BR>float:left; <BR>background-color:#D8D8D8; <BR>border:1px dotted red; <BR>} <BR> <BR>$(document).ready(function(){ <BR>var subject = ""; <BR>var describe = ""; <br><br>//name|="value" <BR>$("#attri1").bind("click",function(){ <BR>var topValue=$("#attri1").offset().top; <BR>subject = "Attribute Contains Prefix Selector [name|=\"value\"]"; <BR>describe = "Selects elements that have the specified attribute with a value either equal to a given string or starting with that string followed by a hyphen (-)."; <BR>$("a[hreflang|='en']").css("border","3px dotted green"); <BR>showMessage(subject,describe,topValue); <BR>}); <br><br>//name*="value" <BR>$("#attri2").bind("click",function(){ <BR>var topValue=$("#attri2").offset().top; <BR>subject = "Attribute Contains Selector [name*=\"value\"]"; <BR>describe = "Selects elements that have the specified attribute with a value containing the a given substring."; <BR>$( "input[name*='man']" ).val( "has man in it!" ); <BR>showMessage(subject,describe,topValue); <BR>}); <br><br>//name~="value" <BR>$("#attri3").bind("click",function(){ <BR>var topValue=$("#attri3").offset().top; <BR>subject = "Attribute Contains Word Selector [name~=\"value\"]"; <BR>describe = "Selects elements that have the specified attribute with a value containing a given word, delimited by spaces."; <BR>$( "input[name~='man']" ).val( "mr. man is in it!" ); <BR>showMessage(subject,describe,topValue); <BR>}); <br><br>//name$="value" <BR>$("#attri4").bind("click",function(){ <BR>var topValue=$("#attri4").offset().top; <BR>subject = "Attribute Ends With Selector [name$=\"value\"]"; <BR>describe = "Selects elements that have the specified attribute with a value ending exactly with a given string. The comparison is case sensitive."; <BR>$( "input[name$='letter']" ).val( "a letter" ); <BR>showMessage(subject,describe,topValue); <BR>}); <br><br>//name="value" <BR>$("#attri5").bind("click",function(){ <BR>var topValue=$("#attri5").offset().top; <BR>subject = "Attribute Equals Selector [name=\"value\"]"; <BR>describe = "Selects elements that have the specified attribute with a value exactly equal to a certain value."; <BR>$( "input[value='Hot Fuzz']" ).next().text( "Hot Fuzz" ); <BR>showMessage(subject,describe,topValue); <BR>}); <br><br>//name$="value" <BR>$("#attri6").bind("click",function(){ <BR>var topValue=$("#attri6").offset().top; <BR>subject = "Attribute Not Equal Selector [name!=\"value\"]"; <BR>describe = "Select elements that either don't have the specified attribute, or do have the specified attribute but not with a certain value."; <BR>$( "input[name!='newsletter']" ).next().append( "<b>; not newsletter" ); <BR>showMessage(subject,describe,topValue); <BR>}); <br><br>//name$="value" <BR>$("#attri7").bind("click",function(){ <BR>var topValue=$("#attri7").offset().top; <BR>subject = "Attribute Starts With Selector [name^=\"value\"]"; <BR>describe = "Selects elements that have the specified attribute with a value beginning exactly with a given string."; <BR>$( "input[name^='news']" ).val( "news here!" ); <BR>showMessage(subject,describe,topValue); <BR>}); <br><br>//name$="value" <BR>$("#attri8").bind("click",function(){ <BR>var topValue=$("#attri8").offset().top; <BR>subject = "Has Attribute Selector [name]"; <BR>describe = "Selects elements that have the specified attribute, with any value.<br><b><font color=\"red\">you can click the div which have id element"; <BR>$( "div[id]" ).one( "click", function() { <BR>var idString = $( this ).text() + " = " + $( this ).attr( "id" ); <BR>$( this ).text( idString ); <BR>}); <BR>showMessage(subject,describe,topValue); <BR>}); <br><br>//name$="value" <BR>$("#attri9").bind("click",function(){ <BR>var topValue=$("#attri9").offset().top; <BR>subject = "Multiple Attribute Selector [name=\"value\"][name2=\"value2\"]"; <BR>describe = "Matches elements that match all of the specified attribute filters."; <BR>$( "input[id][name$='man']" ).val( "only this one" ); <BR>showMessage(subject,describe,topValue); <BR>}); <br><br><BR>}); <br><br>function showMessage(subject,describe,topValue){ <BR>$("#showMessage").html("<font color=\"red\"><b>"+subject+"<br>"+describe) <BR>.addClass("showMessage").css("margin-top",topValue).hide().show(1000); <BR>} <br><br> en en- english name? value? value? name is newsletter no name name is accept no id with id has an id nope