jQuery 屬性選擇器element[herf*='value']使用示例
更新時(shí)間:2013年10月20日 11:11:44 作者:
一個(gè)針對(duì)jQuery屬性選擇器的小例子,增加對(duì)jQUery屬性選擇器的理解,感興趣的朋友可以參考下
一個(gè)針對(duì)jQuery屬性選擇器的小例子,增加對(duì)jQUery屬性選擇器的理解:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<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>
復(fù)制代碼 代碼如下:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<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>
您可能感興趣的文章:
- 詳解element-ui日期時(shí)間選擇器的日期格式化問題
- 詳解關(guān)于element級(jí)聯(lián)選擇器數(shù)據(jù)回顯問題
- element-ui 時(shí)間選擇器限制范圍的實(shí)現(xiàn)(隨動(dòng))
- Element UI框架中巧用樹選擇器的實(shí)現(xiàn)
- vue2.0 element-ui中el-select選擇器無法顯示選中的內(nèi)容(解決方法)
- Vue Element 分組+多選+可搜索Select選擇器實(shí)現(xiàn)示例
- jQuery中元素選擇器(element)簡單用法示例
- jQuery選擇器源碼解讀(七):elementMatcher函數(shù)
- jQuery中element選擇器用法實(shí)例
- 基于Element的組件改造的樹形選擇器(樹形下拉框)
相關(guān)文章
jQuery 移動(dòng)端artEditor富文本編輯器
這篇文章主要介紹了jQuery 移動(dòng)端artEditor富文本編輯器 的相關(guān)資料,需要的朋友可以參考下2016-01-01jQuery ReferenceError: $ is not defined 錯(cuò)誤的處理辦法
今天開始要學(xué)習(xí)jQuery,寫第一個(gè)Hello Word時(shí),居然jQuery ReferenceError: $ is not defined2013-05-05jQuery JSON實(shí)現(xiàn)無刷新三級(jí)聯(lián)動(dòng)實(shí)例探討
無刷新三級(jí)聯(lián)動(dòng)的實(shí)現(xiàn)方法有很多,今天將與大家討論下jQuery JSON如何實(shí)現(xiàn),感興趣的朋友們可以參考下哈2013-05-05jQuery ''行 4954 錯(cuò)誤: 不支持該屬性或方法'' 的問題解決方法
這個(gè)問題只在IE下出現(xiàn)。詭異的是,對(duì)于出現(xiàn)這個(gè)問題的頁面,重新刷新一下就又好了,Ajax 工作一切正常。順便說一下,我的 jQuery 版本是 1.4.2。2011-01-01CSS+Jquery實(shí)現(xiàn)頁面圓角框方法大全
前不久做項(xiàng)目,要用到大量的頁面圓角的框塊,以前實(shí)現(xiàn)的時(shí)候都是用圖片做背景之類的方法,那種方法對(duì)于少數(shù)的還是比較可行的,但是當(dāng)涉及到整個(gè)項(xiàng)目都要用 到這樣的效果時(shí)就顯得不夠優(yōu)化和簡練了。2009-12-12鼠標(biāo)拖動(dòng)實(shí)現(xiàn)DIV排序示例代碼
鼠標(biāo)拖動(dòng)實(shí)現(xiàn)DIV排序的教程有很多,在本文將為大家詳細(xì)介紹個(gè)不錯(cuò)的示例,對(duì)比傳統(tǒng)的排序,這是一個(gè)很不錯(cuò)的嘗試2013-10-10基于jquery的自定義鼠標(biāo)提示效果 jquery.toolTip
看到其它網(wǎng)站A標(biāo)簽title效果,心里癢癢,就想也用到自己網(wǎng)站上。 正好在學(xué)jquery 插件擴(kuò)展,就參照前輩代碼,自己動(dòng)手寫了一個(gè)2010-11-11