一个针对jQuery属性选择器的小例子,增加对jQUery属性选择器的理解:
复制代码 代码如下:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="/UploadFiles/2021-04-02/jquery-1.9.1.js"><style type="text/css">
a{
margin-right:20px;
}
ol{
position:relative;
width:600px;
margin-left:400px;
}
dt{
margin:10px;
height:100px;
background-color:#EAEAEA;
border:3px dotted orange;
}
.showMessage{
width:380px;
float:left;
background-color:#D8D8D8;
border:1px dotted red;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
var subject = "";
var describe = "";
//name|="value"
$("#attri1").bind("click",function(){
var topValue=$("#attri1").offset().top;
subject = "Attribute Contains Prefix Selector [name|=\"value\"]";
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 (-).";
$("a[hreflang|='en']").css("border","3px dotted green");
showMessage(subject,describe,topValue);
});
//name*="value"
$("#attri2").bind("click",function(){
var topValue=$("#attri2").offset().top;
subject = "Attribute Contains Selector [name*=\"value\"]";
describe = "Selects elements that have the specified attribute with a value containing the a given substring.";
$( "input[name*='man']" ).val( "has man in it!" );
showMessage(subject,describe,topValue);
});
//name~="value"
$("#attri3").bind("click",function(){
var topValue=$("#attri3").offset().top;
subject = "Attribute Contains Word Selector [name~=\"value\"]";
describe = "Selects elements that have the specified attribute with a value containing a given word, delimited by spaces.";
$( "input[name~='man']" ).val( "mr. man is in it!" );
showMessage(subject,describe,topValue);
});
//name$="value"
$("#attri4").bind("click",function(){
var topValue=$("#attri4").offset().top;
subject = "Attribute Ends With Selector [name$=\"value\"]";
describe = "Selects elements that have the specified attribute with a value ending exactly with a given string. The comparison is case sensitive.";
$( "input[name$='letter']" ).val( "a letter" );
showMessage(subject,describe,topValue);
});
//name="value"
$("#attri5").bind("click",function(){
var topValue=$("#attri5").offset().top;
subject = "Attribute Equals Selector [name=\"value\"]";
describe = "Selects elements that have the specified attribute with a value exactly equal to a certain value.";
$( "input[value='Hot Fuzz']" ).next().text( "Hot Fuzz" );
showMessage(subject,describe,topValue);
});
//name$="value"
$("#attri6").bind("click",function(){
var topValue=$("#attri6").offset().top;
subject = "Attribute Not Equal Selector [name!=\"value\"]";
describe = "Select elements that either don't have the specified attribute, or do have the specified attribute but not with a certain value.";
$( "input[name!='newsletter']" ).next().append( "<b>; not newsletter</b>" );
showMessage(subject,describe,topValue);
});
//name$="value"
$("#attri7").bind("click",function(){
var topValue=$("#attri7").offset().top;
subject = "Attribute Starts With Selector [name^=\"value\"]";
describe = "Selects elements that have the specified attribute with a value beginning exactly with a given string.";
$( "input[name^='news']" ).val( "news here!" );
showMessage(subject,describe,topValue);
});
//name$="value"
$("#attri8").bind("click",function(){
var topValue=$("#attri8").offset().top;
subject = "Has Attribute Selector [name]";
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</font></b>";
$( "div[id]" ).one( "click", function() {
var idString = $( this ).text() + " = " + $( this ).attr( "id" );
$( this ).text( idString );
});
showMessage(subject,describe,topValue);
});
//name$="value"
$("#attri9").bind("click",function(){
var topValue=$("#attri9").offset().top;
subject = "Multiple Attribute Selector [name=\"value\"][name2=\"value2\"]";
describe = "Matches elements that match all of the specified attribute filters.";
$( "input[id][name$='man']" ).val( "only this one" );
showMessage(subject,describe,topValue);
});
});
function showMessage(subject,describe,topValue){
$("#showMessage").html("<font color=\"red\"><b>"+subject+"</b></font><br>"+describe)
.addClass("showMessage").css("margin-top",topValue).hide().show(1000);
}
</script>
</head>
<body>
<div id="showMessage"></div>
<ol>
<dt>
<input type="button" id="attri1" value="a[hreflang|='en']"/><br><br>
<a href="#" hreflang="en">en</a>
<a href="#" hreflang="en-">en-</a>
<a href="#" hreflang="english">english</a>
</dt>
<dt>
<input type="button" id="attri2" value="name*='man'"/><br><br>
<input name="man-news">
<input name="milkman"><br>
<input name="letterman2">
<input name="newmilk">
</dt>
<dt>
<input type="button" id="attri3" value="input[name~='man']"/><br><br>
<input name="man-news">
<input name="milk man"><br>
<input name="letterman2">
<input name="newmilk">
</dt>
<dt>
<input type="button" id="attri4" value="input[name$='letter']"/><br><br>
<input name="newsletter">
<input name="milkman"><br>
<input name="jobletter">
</dt>
<dt>
<input type="button" id="attri5" value="input[value='Hot Fuzz']"/><br><br>
<div>
<label>
<input type="radio" name="newsletter" value="Hot Fuzz">
<span>name?</span>
</label>
</div>
<div>
<label>
<input type="radio" name="newsletter" value="Cold Fusion">
<span>value?</span>
</label>
</div>
<div>
<label>
<input type="radio" name="newsletter" value="Evil Plans">
<span>value?</span>
</label>
</div>
</dt>
<dt>
<input type="button" id="attri6" value="input[name!='newsletter']"/><br><br>
<div>
<input type="radio" name="newsletter" value="Hot Fuzz">
<span>name is newsletter</span>
</div>
<div>
<input type="radio" value="Cold Fusion">
<span>no name</span>
</div>
<div>
<input type="radio" name="accept" value="Evil Plans">
<span>name is accept</span>
</div>
</dt>
<dt>
<input type="button" id="attri7" value="input[name^='news']"/><br><br>
<input name="newsletter">
<input name="milkman"><br>
<input name="newsboy">
</dt>
<dt>
<input type="button" id="attri8" value="div[id]"/><br>
<div>no id</div>
<div id="hey">with id</div>
<div id="there">has an id</div>
<div>nope</div>
</dt>
<dt>
<input type="button" id="attri9" value="input[id][name$='man']"/><br><br>
<input id="man-news" name="man-news">
<input name="milkman"><br>
<input id="letterman" name="new-letterman">
<input name="newmilk">
</dt>
<dt>
<input type="button" value="clearEffects" onclick="javaScript:window.location.reload();"/>
</dt>
</ol>
</body>
</html>
复制代码 代码如下:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="/UploadFiles/2021-04-02/jquery-1.9.1.js"><style type="text/css">
a{
margin-right:20px;
}
ol{
position:relative;
width:600px;
margin-left:400px;
}
dt{
margin:10px;
height:100px;
background-color:#EAEAEA;
border:3px dotted orange;
}
.showMessage{
width:380px;
float:left;
background-color:#D8D8D8;
border:1px dotted red;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
var subject = "";
var describe = "";
//name|="value"
$("#attri1").bind("click",function(){
var topValue=$("#attri1").offset().top;
subject = "Attribute Contains Prefix Selector [name|=\"value\"]";
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 (-).";
$("a[hreflang|='en']").css("border","3px dotted green");
showMessage(subject,describe,topValue);
});
//name*="value"
$("#attri2").bind("click",function(){
var topValue=$("#attri2").offset().top;
subject = "Attribute Contains Selector [name*=\"value\"]";
describe = "Selects elements that have the specified attribute with a value containing the a given substring.";
$( "input[name*='man']" ).val( "has man in it!" );
showMessage(subject,describe,topValue);
});
//name~="value"
$("#attri3").bind("click",function(){
var topValue=$("#attri3").offset().top;
subject = "Attribute Contains Word Selector [name~=\"value\"]";
describe = "Selects elements that have the specified attribute with a value containing a given word, delimited by spaces.";
$( "input[name~='man']" ).val( "mr. man is in it!" );
showMessage(subject,describe,topValue);
});
//name$="value"
$("#attri4").bind("click",function(){
var topValue=$("#attri4").offset().top;
subject = "Attribute Ends With Selector [name$=\"value\"]";
describe = "Selects elements that have the specified attribute with a value ending exactly with a given string. The comparison is case sensitive.";
$( "input[name$='letter']" ).val( "a letter" );
showMessage(subject,describe,topValue);
});
//name="value"
$("#attri5").bind("click",function(){
var topValue=$("#attri5").offset().top;
subject = "Attribute Equals Selector [name=\"value\"]";
describe = "Selects elements that have the specified attribute with a value exactly equal to a certain value.";
$( "input[value='Hot Fuzz']" ).next().text( "Hot Fuzz" );
showMessage(subject,describe,topValue);
});
//name$="value"
$("#attri6").bind("click",function(){
var topValue=$("#attri6").offset().top;
subject = "Attribute Not Equal Selector [name!=\"value\"]";
describe = "Select elements that either don't have the specified attribute, or do have the specified attribute but not with a certain value.";
$( "input[name!='newsletter']" ).next().append( "<b>; not newsletter</b>" );
showMessage(subject,describe,topValue);
});
//name$="value"
$("#attri7").bind("click",function(){
var topValue=$("#attri7").offset().top;
subject = "Attribute Starts With Selector [name^=\"value\"]";
describe = "Selects elements that have the specified attribute with a value beginning exactly with a given string.";
$( "input[name^='news']" ).val( "news here!" );
showMessage(subject,describe,topValue);
});
//name$="value"
$("#attri8").bind("click",function(){
var topValue=$("#attri8").offset().top;
subject = "Has Attribute Selector [name]";
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</font></b>";
$( "div[id]" ).one( "click", function() {
var idString = $( this ).text() + " = " + $( this ).attr( "id" );
$( this ).text( idString );
});
showMessage(subject,describe,topValue);
});
//name$="value"
$("#attri9").bind("click",function(){
var topValue=$("#attri9").offset().top;
subject = "Multiple Attribute Selector [name=\"value\"][name2=\"value2\"]";
describe = "Matches elements that match all of the specified attribute filters.";
$( "input[id][name$='man']" ).val( "only this one" );
showMessage(subject,describe,topValue);
});
});
function showMessage(subject,describe,topValue){
$("#showMessage").html("<font color=\"red\"><b>"+subject+"</b></font><br>"+describe)
.addClass("showMessage").css("margin-top",topValue).hide().show(1000);
}
</script>
</head>
<body>
<div id="showMessage"></div>
<ol>
<dt>
<input type="button" id="attri1" value="a[hreflang|='en']"/><br><br>
<a href="#" hreflang="en">en</a>
<a href="#" hreflang="en-">en-</a>
<a href="#" hreflang="english">english</a>
</dt>
<dt>
<input type="button" id="attri2" value="name*='man'"/><br><br>
<input name="man-news">
<input name="milkman"><br>
<input name="letterman2">
<input name="newmilk">
</dt>
<dt>
<input type="button" id="attri3" value="input[name~='man']"/><br><br>
<input name="man-news">
<input name="milk man"><br>
<input name="letterman2">
<input name="newmilk">
</dt>
<dt>
<input type="button" id="attri4" value="input[name$='letter']"/><br><br>
<input name="newsletter">
<input name="milkman"><br>
<input name="jobletter">
</dt>
<dt>
<input type="button" id="attri5" value="input[value='Hot Fuzz']"/><br><br>
<div>
<label>
<input type="radio" name="newsletter" value="Hot Fuzz">
<span>name?</span>
</label>
</div>
<div>
<label>
<input type="radio" name="newsletter" value="Cold Fusion">
<span>value?</span>
</label>
</div>
<div>
<label>
<input type="radio" name="newsletter" value="Evil Plans">
<span>value?</span>
</label>
</div>
</dt>
<dt>
<input type="button" id="attri6" value="input[name!='newsletter']"/><br><br>
<div>
<input type="radio" name="newsletter" value="Hot Fuzz">
<span>name is newsletter</span>
</div>
<div>
<input type="radio" value="Cold Fusion">
<span>no name</span>
</div>
<div>
<input type="radio" name="accept" value="Evil Plans">
<span>name is accept</span>
</div>
</dt>
<dt>
<input type="button" id="attri7" value="input[name^='news']"/><br><br>
<input name="newsletter">
<input name="milkman"><br>
<input name="newsboy">
</dt>
<dt>
<input type="button" id="attri8" value="div[id]"/><br>
<div>no id</div>
<div id="hey">with id</div>
<div id="there">has an id</div>
<div>nope</div>
</dt>
<dt>
<input type="button" id="attri9" value="input[id][name$='man']"/><br><br>
<input id="man-news" name="man-news">
<input name="milkman"><br>
<input id="letterman" name="new-letterman">
<input name="newmilk">
</dt>
<dt>
<input type="button" value="clearEffects" onclick="javaScript:window.location.reload();"/>
</dt>
</ol>
</body>
</html>
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年11月18日
2024年11月18日
- 周华健.2015-水浒三部曲原创音乐选辑【滚石】【FLAC分轨】
- 钟志刚《为爱而歌DSD》[WAV+CUE]
- 孙露《情人的眼泪》[低速原抓WAV+CUE]
- 【雨果唱片】刘明源《胡琴专辑》1993[WAV+CUE]
- 黄莺莺《25周年纪念金曲专辑》[WAV+CUE][1.1G]
- 刘德丽《刘德丽新曲+精选》2023[WAV+CUE][1G]
- 潘美辰《鹰与月》双语专辑[WAV+CUE][1G]
- 梁咏琪.2007-女色新曲+精选2CD【华纳】【WAV+CUE】
- 黎亚.2006-我不在巴黎【星外星】【FLAC分轨】
- 陈洁仪.1994-心痛【立得唱片】【WAV+CUE】
- 车载必备专用超级选曲《劲爆中文DJ》2CD[WAV+CUE]
- 群星《民歌流淌60年(黑胶CD)》2CD[WAV+分轨]
- 群星《美丽时光》紫银合金AQCD[WAV+CUE]
- 群星《12大巨星畅销精选集》[WAV分轨][1.1G]
- 华语排行冠军曲《百事音乐风云榜》[WAV+CUE][1G]