1. eq메서드
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;" charset="utf-8" >
<title> jquery </title>
<script src="http://code.jquery.com/jquery-1.7.2.js"></script>
<style type="text/css">
.red{background-color:red;}
</style>
<script>
$(document).ready(function (){
alert($('p').html()); //한개만 읽음C#
alert($('p').text());
alert($('p:eq(2)').text());
alert($('p:eq(2)').html());
});
</script>
</head>
<body>
<p>C#</p>
<p>ASP.NET</p>
<p>jQuery</p>
</body>
</html>
2. is () 메소드
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;" charset="utf-8" >
<title> jquery </title>
<script src="http://code.jquery.com/jquery-1.7.2.js"></script>
<script>
$(document).ready(function (){
//myForm영역에 submit버튼이 있는지 검사
if($('#myForm').children().is("input[type=submit]")){
alert("yes");
}else{
alert("no");
}
});
</script>
</head>
<body>
<div id="myForm">
<input type="text" />
</div>
</body>
</html>
3. 지정된 표현식을 제외한 나머지에 함수 적용하기
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;" charset="utf-8" >
<title> jquery </title>
<style>
.yellow{background-color:yellow;}
</style>
<script src="http://code.jquery.com/jquery-1.7.2.js"></script>
<script>
$(document).ready(function (){
//라디오버튼을 제외한 input태그에 배경색을 yellow로 설정
$('input').not("input[type=radio]").each(function(){
$(this).addClass("yellow").css("border","1px solid red");
});
});
</script>
</head>
<body>
<div id="myForm">
<input type="text" />
<input type="password" />
<input type="radio" />
</div>
</body>
</html>
4. 방금 실행한 집합 이전으로 되돌리기
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;" charset="utf-8" >
<title> jquery </title>
<style>
.yellow{background-color:yellow;}
</style>
<script src="http://code.jquery.com/jquery-1.7.2.js"></script>
<script>
$(document).ready(function (){
//javascript 텍스트 찾아가지1
alert($('div').find('p').html());
//javascript 텍스트 찾아가지1
var result = $('div').find('p:last').find('b').html();
alert(result);
//방금 탐색한 기능 이전으로 돌리기
var html = $('div').find('p:last').find('b').end().html();
alert(html); //jQuery->end() -><b>jQuery</b>
});
</script>
</head>
<body>
<div id="myForm">
<p><b>javascript</b></p>
<p><b>jquery</b></p>
</div>
</body>
</html>
'강좌 > jQuery' 카테고리의 다른 글
제이쿼리(jQuery) - DOM요소의 앞/뒤에 요소 추가 (0) | 2013.04.23 |
---|---|
제이쿼리(jQuery) Manipulation API (0) | 2013.04.23 |
제이쿼리(jQuery) - 폼 요소의 값 가져오기 및 설정 (0) | 2013.04.22 |
jQuery Attributes(jQuery로 요소의 속성 변경하기, 맵 이용) - 3 (0) | 2013.04.22 |
jQuery Attributes(jQuery로 요소의 속성 변경하기) - 2 (0) | 2013.04.22 |