1. Array
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Array</title>
<style type="text/css">
div{color: blue;}
span{color: red;}
</style>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
$(function() {
var arr = [1,"two",3,"four","ldm"];
var $spans = $("span");
$spans.eq(0).text($.inArray("one",arr));
$spans.eq(1).text($.inArray(2,arr));
$spans.eq(2).text($.inArray(3,arr));
$spans.eq(3).text($.inArray("four",arr));
$spans.eq(4).text($.inArray("ldm",arr));
});
</script>
</head>
<body>
<div>"one" 검색 결과 : <span></span></div>
<div>2 검색 결과 : <span></span></div>
<div>3 검색 결과 : <span></span></div>
<div>"four" 검색 결과 : <span></span></div>
<div>"ldm" 검색 결과 : <span></span></div>
</body>
</html>
2. Array Test
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Array Test</title>
<style type="text/css">
*{font-size: 16pt; font-weight: bold;}
div{color: cyan;}
p{color: green; margin: 0;}
</style>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
$(function() {
var months = ["Sunday","Monday","Tuesday","Wedensday",
"Thursday","Friday","Saturday"];
var mons = $.map(months,function(value,indexOrKey){
return value.substr(0,3);
});
$("div").text(months.join(", "));
$("p").text(mons.join(", "));
});
</script>
</head>
<body>
<div></div>
<p></p>
</body>
</html>
3. 맵 형식 테스트
|
|
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>맵 형식 테스트</title>
<style type="text/css">
div{color: red;}
</style>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
$(function() {
$("button").click(function() {
var elems = $("div");
var arr = $.makeArray(elems);
arr.reverse();
$(arr).appendTo(document.body);
});
});
</script>
</head>
<body>
<button>클릭 클릭~~~</button>
<div>First</div>
<div>Second</div>
<div>Third</div>
<div>Fourth</div>
</body>
</html>
4. 서버의 데이타를 대상 엘리먼트에 삽입하기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>서버의 데이타를 대상 엘리먼트에 삽입하기</title>
<style type="text/css">
div{width: 200px; height: 200px;}
</style>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
$(function() {
$("button").click(function() {
$("#container").load("resource.html");
});
});
</script>
</head>
<body>
<button>서버로 부터 데이타 가져오기</button>
<div id="container">데이타 가져오기 전전 ~~~</div>
</body>
</html>
<html>
<b> Happy New Year !!</b>
<resource.html>
5. 서버의 데이타를 대상 엘리먼트에 삽입
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>서버의 데이타를 대상 엘리먼트에 삽입</title>
<style type="text/css">
div{
width: 180px; height: 80px;
margin: 5px; float: left;
}
</style>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
$(function() {
$("#menu1").click(function() {
$("#message1").load("menu.html");
return false;
});
$("#menu2").click(function() {
$("#message2").load("menu.html li");
return false;
});
});
</script>
</head>
<body>
<div>
<a href="#" id="menu1">메뉴 보기 11</a>
<span id="message1"></span>
</div>
<div>
<a href="#" id="menu2">메뉴 보기 22</a>
<span id="message2"></span>
</div>
</body>
</html>
<html>
<p> 중 식 메 뉴 </p>
<ul>
<li> 짜장면 </li>
<li> 짬뽕 </li>
<li> 기스면 </li>
<li> 탕수육 </li>
</ul>
<p> 메뉴를 골라주세요.</p>
<menu.html>
6. 서버 데이타를 대상 엘리먼트에 삽입
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>서버 데이타를 대상 엘리먼트에 삽입</title>
<style type="text/css">
div{
width: 200px; height: 80px;
margin: 5px; float: left;
}
</style>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
$(function() {
$("#menu1").click(function() {
$.ajax({
url:"menu.html",
dataType:"html",
success: function(data) {
$("#message1").html(data);
}
});
return false;
});
$("#menu2").click(function() {
$.ajax({
url:"menu.html",
dataType:"html",
success: function(data) {
$("#message2").html($(data).find('li'));
}
});
return false;
});
});
</script>
</head>
<body>
<div>
<a href="#" id="menu1">메뉴 보기 111</a>
<span id="message1"></span>
</div>
<div>
<a href="#" id="menu2">메뉴 보기 222</a>
<span id="message2"></span>
</div>
</body>
</html>
7. Json Test
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Json Test</title>
<style type="text/css">
td{
border: 1px solid gray;
}
</style>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
$(function() {
$.ajax({
url : "item.json",
dataType : "json",
success : function(data) {
$("#treeData").append(
"<tr><td>id</td>" +
"<td>name</td>" +
"<td>price</td>" +
"<td>description</td>" + "</tr>");
$.each(data,function(){
$("#treeData").append("<tr>" + "<td>"
+ this.id + "</td>" + "<td>"
+ this.name + "</td>" + "<td>"
+ this.price + "</td>" + "<td>"
+ this.description + "</td>" + "</tr>");
});
}
});
});
</script>
</head>
<body>
<table id="treeData"></table>
</body>
</html>
<html>
[
{
"id": "1",
"name": "레몬",
"price": " 3000",
"description": "레몬에 포함되어 있는 쿠엔산은 피로회복에 좋다. 비타민C도 풍부하다."
},
{
"id": "2",
"name": "키위",
"price": " 2000",
"description": "비타민C가 매우 풍부하다. 다이에트와 미용에도 매우 좋다."
},
{
"id": "3",
"name": "블루베리",
"price": " 5000",
"description": "블루베리에 포함된 anthocyanin(안토시아닌)은 눈피로에 효과가 있다."
},
{
"id": "4",
"name": "체리",
"price": " 5000",
"description": "체리는 맛이 단 성분이 많고 피로회복에 잘 듣는다."
},
{
"id": "5",
"name": "메론",
"price": " 5000",
"description": "메론에는 비타민A와 칼륨이 많이 포함되어 있다."
},
{
"id": "6",
"name": "수박",
"price": "15000",
"description": "수분이 풍부한 과일이다."
},
{
"id": "7",
"name": "두리안",
"price": "20000",
"description": "냄새가 고약하다."
}
]
<item.json>
8. JSON Test
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>JSON Test</title>
<style type="text/css">
td{
border : 1px solid gray;
}
</style>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
$(function() {
$.getJSON("item.json",function(data, textStatus){
$("#treeData").append(
"<tr><td>id</td>" + "<td>name</td>"
+"<td>price</td>" + "<td>description</td>" + "</tr>");
$.each(data, function() {
$("#treeData").append("<tr>" + "<td>"
+ this.id + "</td>" + "<td>"
+ this.name + "</td>" + "<td>"
+ this.price + "</td>" + "<td>"
+ this.description + "</td>" + "</tr>");
});
});
});
</script>
</head>
<body>
<table id="treeData"></table>
</body>
</html>
9. $.getJSON으로 데이타 얻기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>$.getJSON으로 데이타 얻기</title>
<style type="text/css">
img{height: 100px; float: left;}
</style>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
$(function() {
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?"
+ "tags=hippo&tagmode=any&format=json&jsoncallback=?",
function(data) {
$.each(data.items,function(i,item){
$("<img />").attr("src",item.media.m).appendTo("#images");
if (i == 4) {
return false;
}
});
});
});
</script>
</head>
<body>
<div id="images"></div>
</body>
</html>
10. XML file get 방식으로 로드
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>XML file get 방식으로 로드</title>
<style type="text/css">
td{
border : 1px solid gray;
}
</style>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
$(function() {
$.get("item.xml",function(data){
$("#treeData").append(
"<tr><td>id</td>" + "<td>name</td>"
+"<td>price</td>" + "<td>description</td>" + "</tr>"
);
$(data).find("item").each(function() {
var $item = $(this);
$("#treeData").append("<tr>" + "<td>"
+$item.attr("id") + "</td>" + "<td>"
+$item.attr("name") + "</td>" + "<td align='right'>"
+$item.find("price").text() + "</td>" + "<td>"
+$item.find("description").text() + "</td>" + "</tr>"
);
});
});
});
</script>
</head>
<body>
<table id="treeData"></table>
</body>
</html>
<html>
<?xml version="1.0" encoding="UTF-8"?>
<items>
<item id="1" name="레몬">
<price>3000</price>
<description> 레몬에 포함되어 있는 쿠엔산은 피로회복에 좋다. 비타민C도 풍부하다. </description>
</item>
<item id="2" name="키위">
<price>2000</price>
<description> 비타민C가 매우 풍부하다. 다이에트와 미용에도 매우 좋다. </description>
</item>
<item id="3" name="블루베리">
<price>5000</price>
<description> 블루베리에 포함된 anthocyanin(안토시아닌)은 눈피로에 효과가 있다. </description>
</item>
<item id="4" name="체리">
<price>5000</price>
<description> 체리는 맛이 단 성분이 많고 피로회복에 잘 듣는다. </description>
</item>
<item id="5" name="메론">
<price>5000</price>
<description> 메론에는 비타민A와 칼륨이 많이 포함되어 있다. </description>
</item>
<item id="6" name="수박">
<price>15000</price>
<description> 수분이 풍부한 과일이다.</description>
</item>
<item id="7" name="두리안">
<price>20000</price>
<description> 냄새가 고약하다.</description>
</item>
</items>
<item.xml>
11. $.ajax 로 jsp 화일 로드
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>$.ajax 로 jsp 화일 로드</title>
<style type="text/css">
td{border: 1px solid gray;}
</style>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
$(function() {
$("#submit").click(function() {
var username = $(".username").val();
var sendData = "username=" + username;
$.post(
"welcome.jsp",
sendData,
function(msg){
$("#message").html(msg);
});
return false;
});
});
</script>
</head>
<body>
<form>
<label>이름을 입력하세요~~~</label>
<input type="text" name="username" class="username"/><br>
<input type="button" id="submit" value="전송"/>
</form>
<div id="message"></div>
</body>
</html>
12. $.ajax 로 jsp 화일 로드
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>$.ajax 로 jsp 화일 로드</title>
<style type="text/css">
td{
border: 1px solid gray;
}
</style>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
$(function() {
$("#submit").click(function() {
var username = $(".username").val();
var pwd = $(".passwd").val();
var email = $(".email").val();
var sendData = "username=" + username + "&password=" + pwd + "&email=" + email;
$.ajaxSetup({
type:"post",
url:"logincheck.jsp",
dataType:"text",
success: function(msg) {
$("#message").html(msg);
}
});
$.ajax({
data: sendData
});
return false;
});
});
</script>
</head>
<body>
<form>
<label>이름을 입력하세요~~</label>
<input type="text" name="username" class="username"/><br/>
<label>암호를 입력하세요</label>
<input type="password" name="password" class="passwd"><br/>
<label>이메일을 입력하세요</label>
<input type="text" name="email" class="email"><br/>
<input type="button" id="submit" value="전송"/>
</form>
<div id="message"></div>
</body>
</html>
<html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!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>Insert title here</title>
</head>
<body>
입력한 아이디는 ${param.username}이며
<c:choose>
<c:when test="${param.username=='admin' && param.password=='1234' && param.email=='korea'}">
당신은 접근 권한이 있습니다.
</c:when>
<c:otherwise>
죄송합니다. 당신은 접근 권한이 없습니다.
</c:otherwise>
</c:choose>
</body>
</html>
<logincheck.jsp>
13. script 로드
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>script 로드</title>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
$(function() {
$.getScript("test.js");
$("#submit").click(function() {
var msg = call($(".username").val(),$(".passwd").val());
$("#message").html(msg);
return false;
});
});
</script>
</head>
<body>
<form>
<label></label>
<input type="text" name="username" class="username"/><br/>
<input type="password" name="passwd" class="passwd"/><br/>
<input type="button" id="submit" value="전송">
<div id="message"></div>
</form>
</body>
</html>
<html>
function call(param1, param2){
return ("Hello, " + param1 +" 비밀번호 : " + param2);
}
<test.js>
14. 폼데이타를 쿼리스트링으로 변환
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>폼데이타를 쿼리스트링으로 변환</title>
<style type="text/css">
div{font-weight: bold; color: red;}
</style>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
/*$(function() {
$("#submit").click(function() {
var form_data = $("form").serialize();
$("#result").text(form_data);
});
});*/
$(function() {
$("#submit").click(function() {
$("#result").empty();
var form_data = $("form").serializeArray();
console.log(form_data);
//.serializeArray();폼 엘리먼트의 값을 객체 배열로 변환한다
$.each(form_data,function(index,value){
$("#result").append(value.name + "=" + value.value + "<br/>")
});
});
});
</script>
</head>
<body>
<hr size="5" color="green">
<form>
<input type="hidden" name="seq" value="1">
<label>이름을 입력하세요</label>
<input type="text" name="username"><br/>
<label>암호를 입력하세요</label>
<input type="password" name="password"/><br/>
<input type="checkbox" name="hobby" value="music"/>music
<input type="checkbox" name="hobby" value="yoga"/>yoga
<input type="checkbox" name="hobby" value="reading"/>reading
<input type="checkbox" name="hobby" value="biking"/>biking<br/>
<input type="button" id="submit" value="전송"/>
</form>
<hr size="5" color="red">
<div id="result"></div>
</body>
</html>
15. Insert title here
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="shortcut icon" type="image/ico"
href="http://www.datatables.net/media/images/favicon.ico"/>
<link rel="media/css/demo_table_jui.css">
<style type="text/css" title="currentStyle">
@import "media/css/demo_page.css";
@import "media/css/demo_table.css";
</style>
<script src="../js/jquery.js" type="text/javascript"></script>
<script src="media/js/jquery.dataTables.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$('#example').dataTable();
});
</script>
</head>
<body>
<table class="display" id="example">
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>price</th>
<th>description</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td><td>레몬</td><td align="right">3000</td>
<td>레몬에 포함되어 있는 쿠엔산은 피로회복에 좋다. 비타민C도 풍부하다.</td>
</tr>
<tr>
<td>2</td><td>두리안</td><td align="right">20000</td>
<td>고약한 냄새가 난다.</td>
</tr>
<tr>
<td>3</td><td>수박</td><td align="right">15000</td>
<td>수분이 많다.</td>
</tr>
<tr>
<td>4</td><td>바나나</td><td align="right">3000</td>
<td>바나나</td>
</tr>
<tr>
<td>5</td><td>레몬</td><td align="right">3000</td>
<td>레몬에 포함되어 있는 쿠엔산은 피로회복에 좋다. 비타민C도 풍부하다.</td>
</tr>
<tr>
<td>6</td><td>레몬</td><td align="right">3000</td>
<td>레몬에 포함되어 있는 쿠엔산은 피로회복에 좋다. 비타민C도 풍부하다.</td>
</tr>
<tr>
<td>7</td><td>레몬</td><td align="right">3000</td>
<td>레몬에 포함되어 있는 쿠엔산은 피로회복에 좋다. 비타민C도 풍부하다.</td>
</tr>
<tr>
<td>8</td><td>레몬</td><td align="right">3000</td>
<td>레몬에 포함되어 있는 쿠엔산은 피로회복에 좋다. 비타민C도 풍부하다.</td>
</tr>
<tr>
<td>9</td><td>레몬</td><td align="right">3000</td>
<td>레몬에 포함되어 있는 쿠엔산은 피로회복에 좋다. 비타민C도 풍부하다.</td>
</tr>
<tr>
<td>10</td><td>레몬</td><td align="right">3000</td>
<td>레몬에 포함되어 있는 쿠엔산은 피로회복에 좋다. 비타민C도 풍부하다.</td>
</tr>
<tr>
<td>11</td><td>레몬</td><td align="right">3000</td>
<td>레몬에 포함되어 있는 쿠엔산은 피로회복에 좋다. 비타민C도 풍부하다.</td>
</tr>
<tr>
<td>12</td><td>레몬</td><td align="right">3000</td>
<td>레몬에 포함되어 있는 쿠엔산은 피로회복에 좋다. 비타민C도 풍부하다.</td>
</tr>
<tr>
<td>13</td><td>레몬</td><td align="right">3000</td>
<td>레몬에 포함되어 있는 쿠엔산은 피로회복에 좋다. 비타민C도 풍부하다.</td>
</tr>
</tbody>
</table>
</body>
</html>
'제이쿼리(jQuery)' 카테고리의 다른 글
4. jQuery (제이쿼리) (0) | 2017.04.19 |
---|---|
3. jQuery (제이쿼리) (0) | 2017.04.18 |
2. jQuery (제이쿼리) (0) | 2017.04.17 |
1. jQuery (제이쿼리) (0) | 2017.04.13 |