jquery 정규식 표현 문자 검색 등

js API/jquery 2012. 4. 19. 10:52
@ value 문자와 일치하되 연속된 글로 연결되지 않은 문자를 찾을 때 
1. Attribute Contains Prefix Selector [name|="value"]
	< a href="example.html" hreflang="en" >Some text< /a> 
	< a href="example.html" hreflang="en-UK">Some other text< /a>
	< a href="example.html" hreflang="english">will not be outlined< /a>

	< script >
		$('a[hreflang|="en"]').css('border','3px dotted green');
	< /script >
// 결과 Some text, Some other text 에만 css가 적용됨 



@ value에 해당하는 문자가 앞,뒤,중간 중 어디에 있어도 상관없이 찾을 때 
2. Attribute Contains Selector [name*="value"]
	< input name="man-news">
	< input name="milkman">
	< input name="letterman2">
	< input name="newmilk">
	
	< script >
		$('input[name*="man"]').val('has man in it!');
	< /script >
// 결과 man-news,milkman,letterman2 만 검색됨 


@ value에 해당하는 문자가 뒤(끝)에 존재하는 것을 찾을 때 
3. Attribute Contains Word Selector [name~="value"]
	< input name="man-news">

	< input name="milk man">
	< input name="letterman2">
	< input name="newmilk">
	
	< script >
		$('input[name~="man"]').val('mr. man is in it!');
	< /script >
// 결과 milk man 


@ value에 해당하는 문자가 뒤(끝)에 존재하는 것을 찾을 때 
4. Attribute Ends With Selector [name$="value"]
	< input name="newsletter">
	< input name="milkman">
	< input name="jobletter">

	< script >
		$('input[name$="letter"]').val('a letter');
	< /script >
// 결과 newsletter,jobletter 


@ value에 해당하는 문자 일치하는 것을 찾을 때 
5. Attribute Equals Selector [name="value"]
	< input type="radio" name="newsletter" value="Hot Fuzz">
	< input type="radio" value="Cold Fusion">
	< input type="radio" name="accept" value="Evil Plans">

	< script >
		$('input[name!="newsletter"]').val());
	< /script >
// 결과 Hot Fuzz 


@ value에 해당하는 문자 일치하지 않는 것을 찾을 때 
6. Attribute Not Equal Selector [name!="value"]
	< input type="radio" name="newsletter" value="Hot Fuzz">
	< input type="radio" value="Cold Fusion">
	< input type="radio" name="accept" value="Evil Plans">

	< script >
		$('input[name!="newsletter"]').val());
	< /script >
// 결과 Cold Fusion, Evil Plans 


@ value로 시작하는 문자를 찾을 때 
7. Attribute Starts With Selector [name^="value"]
	< input type="radio" name="newsletter" value="Hot Fuzz">
	< input type="radio" name="newslog" value="Cold Fusion">
	< input type="radio" name="accept" value="Evil Plans">

	< script >
		$('input[name!="news"]');
	< /script >
// 결과 newsletter, newslog 



 @ 여러개를 동시에 검색할때 
8. Multiple Attribute Selector [name="value"][name2="value2"]