http://tutsplus.com/lesson/hello-jquery/
<script src="js/jquery-1.7.1.js"></script>Âå¤ï¤ê¤ËGoogle Libraries API ¤ò»²¾È
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
[source] [reload] |
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Lesson1</title>
<style type="text/css">
/* ==================== STYLES ==================== */
.emphasis {
color: green;
font-weight: bold;
font-size: large;
text-decoration: underline;
}
/* ==================== STYLES ==================== */
</style>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
/* ==================== SCRIPTS ==================== */
$(document).ready(function(){
// DOM ¥Ä¥ê¡¼¤¬¤Ç¤¤¢¤¬¤Ã¤Æ¤«¤é¼Â¹Ô¤µ¤ì¤ë
jQuery('ul li').css('color','red');
jQuery('ul li').css('font-style','italic');
$('ol li').addClass('emphasis');
});
/* ==================== SCRIPTS ==================== */
</script>
</head>
<body>
<ul>
<li>list1</li>
<li>list2</li>
<li>list3</li>
</ul>
<ol>
<li>list1</li>
<li>list2</li>
<li>list3</li>
</ol>
</body>
</html>
http://tutsplus.com/lesson/not-so-fast-jquery/
$(document).ready(function(){ // DOM Áàºî });
$(function(){ // DOM Áàºî });
http://tutsplus.com/lesson/the-basics-of-querying-the-dom/
[source] [reload] |
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Lesson3</title>
<style type="text/css">
/* ==================== STYLES ==================== */
.headerClass {
color: green;
font-weight: bold;
font-size: large;
text-decoration: underline;
}
.footerClass {
padding-top: 20px;
vertical-align: bottom;
font-size: small;
}
/* ==================== STYLES ==================== */
</style>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
/* ==================== SCRIPTS ==================== */
$(document).ready(function(){
// ¡id »ØÄê
$('#header').addClass('headerClass');
// ¢class »ØÄê
$('#footer').css('color', 'gray');
// £tag »ØÄê
$('table').css('border-spacing','0');
// ¤Â°À»ØÄê
$('[type="text"]').css('text-align','right');
// ¥»ÒÍ×ÁÇ
$('table thead tr').children().css('background','orange');
// §·«¤êÊÖ¤·
$('table tbody tr').each(function(index){
// ¦Í×ÁÇÈÖ¹æ»ØÄê
$(this).children().eq(0).text(index + 1);
if (index % 2) {
$(this).children().css('background','ivory');
}
});
});
/* ==================== SCRIPTS ==================== */
</script>
</head>
<body>
<div id="header">
<h1>ACME SHOPPING SITE</h1>
</div>
<div id="body">
<table border="1">
<thead>
<tr>
<th>No.</th>
<th>ÉÊ̾</th>
<th>ñ²Á</th>
<th>¸Ä¿ô</th>
<th>¹ç·×</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td>Ultra Marker</td>
<td>100</td>
<td><input type="text" size="5" value="0"/></td>
<td>0</td>
</tr>
<tr>
<td></td>
<td>Ultimate Eraser</td>
<td>300</td>
<td><input type="text" size="5" value="0"/></td>
<td>0</td>
</tr>
<tr>
<td></td>
<td>Super Pencil</td>
<td>50</td>
<td><input type="text" size="5" value="0"/></td>
<td>0</td>
</tr>
<tr>
<td></td>
<td>Hyper Card</td>
<td>150</td>
<td><input type="text" size="5" value="0"/></td>
<td>0</td>
</tr>
</tbody>
<tfoot>
<tr>
<th colspan="4">¹ç·×</th>
<th>0</th>
</tr>
</tfoot>
</table>
</div>
<div id="footer" class="footerClass">
Copyright(c) ACME CO LTD 2012 All Rights Reserved.
</div>
</body>
</html>
¡ | id»ØÄê | $('#id') | |
¢ | class»ØÄê | $('.class') | |
£ | tag»ØÄê | $('tag'), $('tag tag') | |
¤ | °À»ØÄê | $('[arg="val"]') | ´°Á´°ìÃ×(=)¡¢ÈÝÄê°ìÃ×(!=)¡¢ÀèƬ°ìÃ×(^=)¡¢ËöÈø°ìÃ×($=)¡¢Éôʬ°ìÃ×(*=) |
¥ | »ÒÍ×ÁǤν¸¹ç | $('tag').children() | |
¦ | nÈÖÌܤλÒÍ×ÁÇ | $('tag').children().eq(n) | ºÇ½é¤ÎÍ×ÁÇ¤Ï 0 |
§ | ·«¤êÊÖ¤·½èÍý | $('tag').each(function(index){ ... }) | index¤ÏÍ×ÁÇÈֹ档 ·«¤êÊÖ¤·Í×ÁÇ¤Ï this ¤ËÆþ¤ë¡£this ¤Ï Javascript ¤ÎÀ¸¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ê¤Î¤Ç¡¢jQuery ¤Î´Ø¿ô¤ò»È¤¦¤Ë¤Ï $(this) ¤³¤ÎÍ×ÁǤǽèÍý¤òÃæÃǤ¹¤ë¾ì¹ç¤Ï return false;¡£return; ¤Ë¤¹¤ë¤È¼¡¤Î·«¤êÊÖ¤·¤ËÆþ¤ë |
¨ | ľ¶á¤ÎÁÄÀèÍ×ÁÇ | $('tag').closest('parent') | |
© | Á°¸å¤ÎÍ×ÁÇ | $('tag').next(), $('tag').prev() | |
ª | Á°¸å¤ÎÍ×ÁǤν¸¹ç | $('tag').nextAll(), $('tag').prevAll() | |
« | »ÒÍ×ÁǤθ¡º÷ | $('tag').find('.class') | <tag> ÇÛ²¼¤«¤é .class ¤Î¥Î¡¼¥É¤òÁܤ¹¡£$('tag .class')¤ÈƱ¤¸ |
¬ | Í×Áǽ¸¹ç¤«¤é¤Î¸¡º÷ | $('tag').filter('.class') | Á´¤Æ¤Î <tag> ¤ÎÃ椫¤é¡¢class¤¬ .class ¤Î¤â¤Î¤òÁܤ¹ |
| Í×Áǽ¸¹ç¤«¤é¤Î¸¡º÷ | $('tag').not('.class') | Á´¤Æ¤Î <tag> ¤ÎÃ椫¤é¡¢class¤¬ .class ¤Ç¤Ê¤¤¤â¤Î¤òÁܤ¹ |
form | :input¡¢:text¡¢:radio¡¢:checkbox¡¢:password¡¢:submit¡¢:image¡¢:reset¡¢:button¡¢:file¡¢:hidden |
¾õÂÖ | :checked¡¢:selected¡¢:visible¡¢:enable¡¢:disabled¡¢:animated |
»ÒÍ×ÁÇ»ØÄê | :first¡¢:last¡¢:even¡¢:odd¡¢:eq(n)¡¢:gt(n)¡¢:lt(n) |
¾ | :has(selector) <-- selector Í×ÁǤò´Þ¤à |
:contains(text) <-- text ¤ò´Þ¤à | |
:parent(selector) <-- selector ¤Î¿ÆÍ×ÁÇ | |
:header(selector) <-- H1¡¢H2¡¢H3 ¤Î¤³¤È |
$('#id').css('color','red'); $('#id').text('abc');
var abc = $('#id'); abc.css('color','red'); abc.text('abc');
°À¼èÆÀ | var argVal = $('#id').attr('arg'); | |
°ÀÀßÄê | $('#id').attr('arg','argval'); | |
¥¯¥é¥¹Äɲà | $('#id').addClass('class'); | |
¥¯¥é¥¹ºï½ü | $('#id').removeClass('class'); | |
¥¯¥é¥¹¹¹¿· | $('#id').toggleClass('class'); | ¤¹¤Ç¤Ë class ¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ì¤Ðºï½ü¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð class ¤òÄɲà |
CSS¼èÆÀ | var css = $('#id').css('font-size'); | |
CSSÊѹ¹ | $('#id').css('font-size','10'); | |
°ÌÃÖ¼èÆÀ | alert($('#id').offset().top + "," + $('#id').offset().left) | |
Â礤µ¼èÆÀ | alert($('#id').width() "," + $('#id').height() | |
Â礤µ¹¹¿· | $('#id').width(400); $('#id').height(300); | |
DOM¼èÆÀ | var div = $('#header').get(); var div = $('div').get(0); | |
HTML¼èÆÀ | var div = $('#header').html(); | |
HTMLÀßÄê | $('#header').html('<h1>HELLO</h1>'); | |
TEXT¼èÆÀ | var text = $('#msg').text(); | |
TEXTÀßÄê | $('#msg').html('HELLO'); | |
VALUE¼èÆÀ | var val = $('#price').val(); | |
VALUEÀßÄê | $('#price').val('$9.99'); | |
DATA¼èÆÀ | var data = $('#id').data('key'); | jQuery¤Ï¡¢DOM¥Î¡¼¥É¤ò¼èÆÀ¤¹¤ëºÝ¤Ë data ¤ò³ÊǼ¤Ç¤¤ë¤è¤¦¤Ë³ÈÄ¥¤¹¤ë¡£ ¥¤¥Ù¥ó¥È¥Ï¥ó¥É¥é¤Ê¤É¤â¤³¤³¤Ë³ÊǼ¤µ¤ì¤ë(°ìÈ̥ǡ¼¥¿¤ò³ÊǼ¤¹¤ë¥¡¼¤Ë 'event'¡¢'handle' ¤ò»È¤Ã¤Æ¤Ï¤¤¤±¤Ê¤¤)¡£ ¤¢¤È¡¢¤Ç¤«¤¤¥Ç¡¼¥¿¤òÃÖ¤¤¤¿¤é¤¤¤«¤ó¤è |
DATAÀßÄê | $('#id').data('key','val'); | |
DATAºï½ü | $('#id').removeData('key'); | °ú¿ô¤Ê¤·¤Ç removeData() ¤ò¸Æ¤Ó½Ð¤¹¤È¡¢jQuery ¤Ë¤è¤ë³ÈÄ¥¤¬Á´¤Æºï½ü¤µ¤ì¤ë¤Î¤Ç¡¢É¬¤º°ú¿ôÉÕ¤¤Ç¸Æ¤Ó½Ð¤¹¡£ undefined¡¢null¡¢0 ¤ò°ú¿ô¤Ë»ØÄꤹ¤ë¤È¡¢°ú¿ô¤Ê¤·¤È¸«¤Ê¤µ¤ì¤ë |
[source] [reload] |
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Lesson4</title>
<style type="text/css">
/* ==================== STYLES ==================== */
.day {
color: black;
background : yellow;
}
.night {
color: white;
background : black;
}
/* ==================== STYLES ==================== */
</style>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
/* ==================== SCRIPTS ==================== */
$(document).ready(function(){
// <body> ¤ò¥¥ã¥Ã¥·¥å¤¹¤ë¡£
// javascript ¤Î function ¤Ï¥¯¥í¡¼¥¸¥ã¡¼¤Ê¤Î¤Ç¡¢´Ø¿ô¤¬¾õÂÖ¤ò»ý¤Æ¤ë¡£¢ª ¤³¤³¤Ç¥¥ã¥Ã¥·¥å¤·¤ÆÎɤ¤
var body = $('body');
body.addClass('day');
// $('button').click(function() {...}) ¤È¤â½ñ¤±¤ë
$('button').on('click', function() {
// button ¥¯¥ê¥Ã¥¯»þ¤Î¥¤¥Ù¥ó¥È¥Ï¥ó¥É¥é
// ¥¤¥Ù¥ó¥È¥½¡¼¥¹¤Î DOMÍ×ÁÇ¤Ï this
// jQurye ³ÈÄ¥¤ò¤¹¤ë¤¿¤á¤Ë $(this) ¤¹¤ë
// jQuery ³ÈÄ¥¤µ¤ì¤¿ this ¤Ï $this ¤È¤¹¤ë̿̾µ¬Ìó¤Ë¤¹¤ë¤È¤è¤í¤·
var $this = $(this);
var stylesheet = $this.data('css');
body.removeClass();
body.addClass(stylesheet);
$this
.siblings() // ¼«Ê¬°Ê³°¤Î·»Äï¥Î¡¼¥É¤òÊÖ¤¹
.removeAttr('disabled')
.end() // <-- This is tricky jargon of jQueyr.
.attr('disabled', 'disabled');
});
});
/* ==================== SCRIPTS ==================== */
</script>
</head>
<body>
<h1>My Website</h1>
<button data-css="day" disabled>Day</button>
<button data-css="night">Night</button>
</body>
</html>
$(element).on('event', function(){ ... });
$(element).off('event');
¥¤¥Ù¥ó¥È | ¥¤¥Ù¥ó¥È̾ | È÷¹Í | |
¥Õ¥©¡¼¥«¥¹ | ÆÀ¤ë | focus, focusin | |
¼º¤¦ | blur, focusout | ||
¥Ú¡¼¥¸ | Æɤ߹þ¤ß | load | |
Á«°Ü | unload | ¥Ú¡¼¥¸Á«°Ü¤È¥Ö¥é¥¦¥¶½ªÎ»¤Çµ¯¤¤ë¥¤¥Ù¥ó¥È¡£Î¾¼Ô¤Ï¶èÊ̤Ǥ¤Ê¤¤¤Î¤Ç¥Ö¥é¥¦¥¶½ªÎ»È½Äê¤ÏÆñ¤·¤¤ | |
Â礤µÊѹ¹ | resize | ||
¥¹¥¯¥í¡¼¥ë | scroll | ||
¥¯¥ê¥Ã¥¯ | click | ||
¥À¥Ö¥ë¥¯¥ê¥Ã¥¯ | dblclick | ||
¥Þ¥¦¥¹ | ¥Ü¥¿¥ó²¡¤·¤¿ | mousedown | |
¥Ü¥¿¥óÊü¤·¤¿ | mouseup | ||
°ÜÆ° | mousemove | ||
Æþ¤Ã¤¿ | mouseover, mouseenter | ||
½Ð¤¿ | mouseout, mouseleave | ||
ÃÍÊѹ¹ | change | ||
ÁªÂò¤µ¤ì¤¿ | select | ||
Form Submit | submit | "form.onReset = function(){...}" ¤Ï jQuery ¤Ç¤Ï»ØÄê¤Ç¤¤Ê¤¤ | |
¥¡¼ | ²¡¤¹ | keydown | |
²¡¤·¤Æ¤¤¤ë | keypress | ||
Êü¤·¤¿ | keyup | ||
¥¨¥é¡¼È¯À¸ | error | window.onerror()(Á´ÂÎŪ¤Ê¥¨¥é¡¼),image.onerror()(²èÁüÆɤ߹þ¤ß¼ºÇÔ) ¤Ê¤É | |
±¦¥¯¥ê¥Ã¥¯¥á¥Ë¥å¡¼¸Æ¤Ó½Ð¤·»þ | contextmenu | false ¤òÊÖ¤¹¤È±¦¥¯¥ê¥Ã¥¯¥á¥Ë¥å¡¼(contextmenu)¤Ïɽ¼¨¤µ¤ì¤Ê¤¤ |
$this .siblings() // ¼«Ê¬°Ê³°¤Î·»Äï¥Î¡¼¥É¤òÊÖ¤¹ .removeAttr('disabled') .end() // <-- This is tricky jargon of jQueyr. .attr('disabled', 'disabled');
${·»Äï¥Î¡¼¥É} .removeAttr('disabled') .end() // <-- This is tricky jargon of jQueyr. .attr('disabled', 'disabled');
${·»Äï¥Î¡¼¥É} .end() // <-- This is tricky jargon of jQueyr. .attr('disabled', 'disabled');
$this .attr('disabled', 'disabled');
http://tutsplus.com/lesson/events-201/
[source] [reload] |
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Lesson5</title>
<style type="text/css">
/* ==================== STYLES ==================== */
dl {
width: 300px;
}
dt {
cursor: pointer;
width: 300px;
font-weight: bold;
background: lavender;
border-top: 1px solid white;
border-bottom: 1px solid gray;
}
dd {
margin: 0;
cursor: pointer;
width: 300px;
font-weight: bold;
background: lightyellow;
border-top: 1px solid white;
border-bottom: 1px solid gray;
display: none;
}
/* ==================== STYLES ==================== */
</style>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
/* ==================== SCRIPTS ==================== */
$(document).ready(function(){
$('dl').on('mouseover', 'dt', function() {
$(this)
.next() // <-- next() returns the next dd
.slideDown(200) // <-- gradually show ovew 200ms
.siblings('dd') // <-- all other dd
.slideUp(200); // <-- gradually hide over 200ms
});
$('dl').on('mouseout', function() {
$(this).find('dd').slideUp(200);
});
});
/* ==================== SCRIPTS ==================== */
</script>
</head>
<body>
¢¥Þ¥¦¥¹¥Ý¥¤¥ó¥¿¤ò´Á»ú¤Ë¹ç¤ï¤»¤Æ¤ß¤Æ
<dl>
<dt>»³¸¶¿å·Ü</dt>
<dd>¤ä¤ó¤Ð¤ë¤¯¤¤¤Ê</dd>
<dt>ÌÚè¹</dt>
<dd>¤ß¤ß¤º¤¯</dd>
<dt>ÅÎó¤</dt>
<dd>¤Û¤È¤È¤®¤¹</dd>
<dt>üê</dt>
<dd>¤¯¤Þ¤¿¤«</dd>
<dt>æÇ¿é</dt>
<dd>¤«¤ï¤»¤ß</dd>
</dl>
</body>
</html>
dt { border-top: 1px solid white; border-bottom: 1px solid gray; }¾å¤ËÇö¤¤¿§¤Î border ¤òÀßÄꤷ¤Æ¡¢²¼¤ËÇ»¤¤¿§¤Î border ¤òÀßÄꤹ¤ë¤È¡¢Î©ÂÎŪ¤Ã¤Ý¤¯¸«¤¨¤ë
$('dl dt').on('mouseover', function() { ... });
$('dl').on('mouseover', 'dt', function() { ... });
±£¤¹ | $('id').hide() |
ɽ¼¨¤¹¤ë | $('id').show() |
±£¤¹ | $('id').slideUp() |
ɽ¼¨¤¹¤ë | $('id').slideDown() |
±£¤¹ | $('id').fadeOut() |
ɽ¼¨¤¹¤ë | $('id').fadeIn() |
http://tutsplus.com/lesson/bind-live-delegate-huh/
jQuery.fn.extend({ ... bind: function( types, data, fn ) { return this.on( types, null, data, fn ); }, unbind: function( types, fn ) { return this.off( types, null, fn ); }, live: function( types, data, fn ) { jQuery( this.context ).on( types, this.selector, data, fn ); return this; }, die: function( types, fn ) { jQuery( this.context ).off( types, this.selector || "**", fn ); return this; }, delegate: function( selector, types, data, fn ) { return this.on( types, selector, data, fn ); }, undelegate: function( selector, types, fn ) { // ( namespace ) or ( selector, types [, fn] ) return arguments.length == 1? this.off( selector, "**" ) : this.off( types, selector, fn ); }, ...
$('#id').on('event', function(){...}); $('#id').on('event', 'selector', function(){...});
$('#id').off('event'); $('#id').off('event', 'selector');
http://tutsplus.com/lesson/creating-and-appending-content/
[source] [reload] |
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Lesson8</title>
<style type="text/css">
/* ==================== STYLES ==================== */
table, td, th {
border: 1px darkblue solid;
border-spacing: 0;
}
button.up {
color: white;
background-color: red;
}
button.up:hover {
background-color: darkred;
}
button.up:disabled {
background-color: pink;
}
button.down {
color: white;
background-color: blue;
}
button.down:hover {
background-color: darkblue;
}
button.down:disabled {
background-color: lavender;
}
/* ==================== STYLES ==================== */
</style>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
/* ==================== SCRIPTS ==================== */
$(document).ready(function(){
$('button.up').on('click',function(){
onUpButtonClicked($(this));
});
$('button.down').on('click',function(){
onDownButtonClicked($(this));
});
$('button#addTop').on('click',function(){
// tbody ¤Î»ÒÍ×ÁǤÎÀèƬ¤ËÄɲÃ
$('tbody').prepend(createQueueRow());
disbleTopAndBottomButton();
});
$('button#addBottom').on('click',function(){
// tbody ¤Î»ÒÍ×ÁǤÎËöÈø¤ËÄɲÃ
$('tbody').append(createQueueRow());
disbleTopAndBottomButton();
});
disbleTopAndBottomButton();
});
function onUpButtonClicked(btnComponet) {
var row = btnComponet.closest('tr');
// Á°¤Î tr ¤ÎÁ°¤Ë°ÜÆ°¤¹¤ë
row.prev().before(row);
disbleTopAndBottomButton();
}
function onDownButtonClicked(btnComponent) {
var row = btnComponent.closest('tr');
// ¼¡¤Î tr ¤Î¼¡¤Ë°ÜÆ°¤¹¤ë
row.next().after(row);
disbleTopAndBottomButton();
}
function disbleTopAndBottomButton() {
$('button').removeAttr('disabled');
$('button.up').first().attr('disabled','disabled');
$('button.down').last().attr('disabled','disabled');
}
function createQueueRow() {
var order = $('#order')[0].value;
if (order == '') {
return;
}
$('#order')[0].value = '';
var tr = $('<tr></tr>');
// 1ÎóÌÜ
var td1 = $('<td></td>');
var downBtn = $('<button></button>',{
class: 'down',
text: '¢'
});
var upBtn = $('<button></button>',{
class: 'up',
text: '¢¬'
});
td1.append(downBtn);
td1.append('\n'); // ¸«¤¿ÌܤΤ¿¤á HTML ¤Ë¹ç¤ï¤»¤Æ²þ¹Ô¤òÆþ¤ì¤ë
td1.append(upBtn);
tr.append(td1);
// 2ÎóÌÜ
var td2 = $('<td></td>');
td2.append(order);
tr.append(td2);
// ¥¤¥Ù¥ó¥È¥Ï¥ó¥É¥éÄɲÃ
upBtn.on('click',function(){
onUpButtonClicked($(this));
});
downBtn.on('click',function(){
onDownButtonClicked($(this));
});
return tr;
}
/* ==================== SCRIPTS ==================== */
</script>
</head>
<body>
<table class="table">
<thead>
<tr><th></th><th>Task Queue</th></tr>
</thead>
<tbody>
<tr>
<td>
<button class="down">¢</button>
<button class="up">¢¬</button>
</td>
<td>¥Ó¡¼¥ë</td>
</tr>
<tr>
<td>
<button class="down">¢</button>
<button class="up">¢¬</button>
</td>
<td>ÆüËܼò</td>
</tr>
<tr>
<td>
<button class="down">¢</button>
<button class="up">¢¬</button>
</td>
<td>¥¦¥¤¥¹¥¡¼</td>
</tr>
</tbody>
<tfoot>
</tfoot>
</table>
<hr/>
<input id="order" type="text" placeholder="¤´Ãíʸ"/>
<button id="addTop">¤¹¤°Íߤ·¤¤</button>
<button id="addBottom">¤¢¤È¤Ç¤Ç¤¤¤¤¤è</button>
</body>
</html>
p ¤Î»ÒÍ×ÁǤȤ·¤Æ c ¤òÄɲà | ÀèƬ | p.prepend(c), c.prependTo(p) |
ËöÈø | p.append(c), c.appendTo(p) | |
b ¤Î·»ÄïÍ×ÁǤȤ·¤Æ c ¤òÄɲà | Á° | p.before(c), c.insertBefore(c) |
¸å | p.after(c), c.insertAfter(b) |
http://tutsplus.com/lesson/slides-and-structure/
[source] [reload] |
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Lesson9</title>
<style type="text/css">
/* ==================== STYLES ==================== */
#orderForm {
width: 300px;
font-size: 10px;
background: lightgray;
padding: 1em 2em;
position: relative;
}
/* Javascript ¤¬Í¸ú¤Ê¤È¤¤Î¤ß CSS ¤òŬÍѤ¹¤ë¥Æ¥¯¥Ë¥Ã¥¯ */
.js #orderForm {
position: absolute;
top: 0;
display: none;
}
#orderForm h2 { margin-top: 0; }
#orderForm ul { padding: 0; }
#orderForm li {
list-style: none;
margin-bottom: 1em;
}
.btnClose {
position: absolute;
right: 10px;
top: 10px;
border: 1px solid;
font-size: 0.5em;
cursor: pointer;
}
/* Form inputs */
input, textarea { width: 100%; line-height: 2em;}
input[type=submit] { width: auto; text-align:right;}
label { color: black; display: block; text-align: left; }
/* ==================== STYLES ==================== */
</style>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
/* ==================== SCRIPTS ==================== */
$(document).ready(function(){
// Javascript ¤¬Í¸ú¤Ê¤È¤¤Ë¡¢ÆÃÄê¤Î CSS ¤òŬÍѤ·¤¿¤¤¤È¤¤Î¥Æ¥¯¥Ë¥Ã¥¯
$('html').addClass('js');
formWindow.init($('#orderForm') , {
effect : 'fadeToggle',
speed : 1000
});
});
var formWindow = {
container : null,
config: {
effect: 'slideToggle',
speed: 500
},
init : function(container, config) {
this.container = container;
if (config) {
$.extend(this.config, config);
}
// ¡ß¥Ü¥¿¥ó
$('<span> X </span>')
.prependTo(container)
.on('click', this.close)
.addClass('btnClose');
// Formɽ¼¨¥Ü¥¿¥ó
$('<button></button>', {
text: 'ORDER HERE!'
})
.insertAfter(container.before())
.on('click', this.show);
},
show : function() {
var obj = formWindow.container;
var fnc = formWindow.config.effect;
var arg = formWindow.config.speed;
// javascript ¤Î reflection
obj[fnc](arg);
},
close : function() {
var obj = formWindow.container;
var fnc = formWindow.config.effect;
var arg = formWindow.config.speed;
// javascript ¤Î reflection
obj[fnc](arg);
}
}
/* ==================== SCRIPTS ==================== */
</script>
</head>
<body>
<div id="header">
<h1>ACME DREAM HEAD MASSAGER</h1>
</div>
<div id="body">
<p>This scalp massager will take you to ultimate relaxing place.</p>
<p>Specialized 12 fingers will bend to fit your head skin.
They are glide smoothly across the surface of your scalp, and improve your blood circulations.
This technology was developed by NASA and deployed to the ISS(International Space Station).</p>
<p>Usually, it is 1000 Perica for one, but now it is 1000 Perica for two.
Don't miss this chance. </p>
</div>
<div id="orderForm">
<h2>Order Form</h2>
<form action="#">
<ul>
<li>
<label for="name">Name: </label>
<input name="name" id="name">
</li>
<li>
<label for="emal">Email Address: </label>
<input name="email" id="email">
</li>
<li>
<label for="address">Address: </label>
<input name="address" id="address">
</li>
<li>
<label for="creditcard">Credit Card: </label>
<input name="card" id="card">
</li>
<li>
<label for="amount">Amount: </label>
<input name="amount" id="amount">
</li>
<li>
<input type="submit" value="Submit">
</li>
</ul>
</form>
</div>
</body>
</html>
.js #orderForm { position: absolute; top: 0; display: none; }
$('html').addClass('js');
var obj = formWindow.container; var fnc = formWindow.config.effect; var arg = formWindow.config.speed; obj[fnc](arg);obj ¤Î fnc ¤ò°ú¿ô arg ¤Ç¸Æ¤Ó½Ð¤¹
http://tutsplus.com/lesson/the-this-keyword/
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Lesson10</title>
<style type="text/css">
/* ==================== STYLES ==================== */
/* ==================== STYLES ==================== */
</style>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
/* ==================== SCRIPTS ==================== */
function fn(e) {
e.preventDefault();
console.log("----- in fn(), this is");
console.log(this);
}
var obj = {
fn1 : function(e) {
e.preventDefault();
console.log("----- in obj.fn1(), this is");
console.log(this);
obj.fn2();
},
fn2 : function() {
console.log("----- in obj.fn2(), this is");
console.log(this);
}
}
$(document).ready(function(){
console.log("in ready(), this is");
console.log(this);
$('a#fn').on('click', fn);
$('a#obj').on('click', obj.fn1);
$('a#proxy').on('click', $.proxy(obj.fn1, obj));
});
/* ==================== SCRIPTS ==================== */
</script>
</head>
<body>
<a id="fn" href="http://www.google.com/">Call fn()</a><br/>
<a id="obj" href="http://www.google.com/">Call obj.fn1()</a><br/>
<a id="proxy" href="http://www.google.com/">Call proxy(obj.fn1())</a><br/>
</body>
</html>
¢ª Day 11 °Ê¹ß : Javascript Learn jQuery in 30 Days (11-20)