<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery를 사용한 한줄 메모장 </title>
<link href="pagedtable.css" rel="stylesheet" type="text/css" />
<script src="../../js/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script>
<script src="pagedtable.js" type="text/javascript"></script>
<script type="text/javascript">
$.ajaxSetup({
type: 'post',
dataType: 'json',
contentType: "application/json; charset=utf-8"
});
$(document).ready(function () {
DisplayData();
$('#btnAdd').click(btnAdd_Click);
});
function DisplayData() {
$.ajax({
url: "MemoService.asmx/GetMemos",
cache: false,
data: "{}", // "{page:0}"
success: handleHtml,
error: ajaxFailed
});
}
function handleHtml(data, status) {
$('#ctlMemoList').empty();
var table =
"<table border='1'><thead><tr><th>번호</th><th>이름</th><th>작성일</th></tr></thead>";
$.each(data.d, function (index, entry) {
//날짜 형식 변경
var today = new Date(DateDeserialize(entry["PostDate"]));
var month = (today.getMonth() + 1) < 10
? "0" + (today.getMonth() + 1) :
(today.getMonth() + 1);
var day = today.getDate() < 10 ? "0" +
today.getDate() : today.getDate(); // 일I
table += '<tr class="search' + entry["Num"] + '">';
table += '<td>' + entry["Num"] + '</td>';
table += '<td>' + entry["Name"] + '</td>';
table += '<td>' + today.getFullYear()
+ "-" + month + "-" + day + '</td>';
table += '</tr>';
var tt = '<div id="tooltip-layer' + entry["Num"]
+ '" style="display:none;width:200px;height:100px;'
+ 'border:1px solid gray;background-color:white;">'
+ entry["Title"] + '</div>';
$('#ctlTooltip').append(tt); //
});
table += "</table>";
$('#ctlMemoList').append(table);
//[!] 페이징 처리의 기본은 ('').pageable();
$('table:eq(0)').pageable({
limit: 2, //
pagelimit: 10,
started: 1
});
$.each(data.d, function (index, entry) {
// 툴팁을 띄어보자
$(".search" + entry["Num"]).mouseover(function (e) {
$(this).mousemove(function (e) {
$(this).css("cursor", "hand");
var t = e.clientY - 15; // 상단에 표시
var l = e.clientX + 20; //
$("#tooltip-layer" + entry["Num"])
.css({ "top": t, "left": l, "position":
"absolute", "opacity": "0.8" })
.show();
});
});
$(".search" + entry["Num"]).mouseout(function () {
$("#tooltip-layer" + entry["Num"]).hide();
});
});
}
function ajaxFailed(xmlRequest) {
alert(
xmlRequest.status + '\r\n' + xmlRequest.statusText + '\r\n' + xmlRequest.responseText);
}
function DateDeserialize(dateStr) {
return eval('new' + dateStr.replace(/\//g, ' '));
}
function btnAdd_Click() {
var name = $('#txtName').val();
var email = $('#txtEmail').val();
var title = $('#txtTitle').val();
if (name.length == 0) {
alert("이름을 입하시오."); return;
}
var postVal = "{name:\"" + name + "\",
email:\"" + email + "\", title:\"" + title + "\"}";
$.ajax({
url: "MemoService.asmx/AddMemo",
data: postVal,
success: function (data) {
alert('저장완료');
$('#txtName').val('');
$('#txtEmail').val("");
$('#txtTitle').val('');
DisplayData(); // 재c 로¤I드ìa
}
});
}
</script>
</head>
<body>
<h3>한줄 메모장</h3>
이름 : <input id="txtName" type="text" />
이메일 : <input id="txtEmail" type="text" />
메모 : <input id="txtTitle" type="text" />
<input id="btnAdd" type="button" value="메모 남기기" />
<hr />
<div id="ctlMemoList">여긱에 메모 리스트 출력</div>
<div id="ctlTooltip"></div>
</body>
</html>
|