jquery

73
Jiayun Zhou 2008.11.22 TWJUG

Upload: koji-lin

Post on 13-Jan-2015

3.991 views

Category:

Technology


2 download

DESCRIPTION

taiwan java user groupJQuery

TRANSCRIPT

Page 1: JQuery

Jiayun Zhou2008.11.22

TWJUG

Page 2: JQuery

JavaScript Library

Page 3: JQuery
Page 4: JQuery
Page 5: JQuery
Page 6: JQuery
Page 7: JQuery
Page 8: JQuery
Page 9: JQuery
Page 10: JQuery

Query

Page 11: JQuery

Database?

Page 12: JQuery

SQL?

Page 13: JQuery

Select...

Page 14: JQuery
Page 15: JQuery

document.getElementById("id")

Page 16: JQuery

document.getElementById("id")

jQuery: $("#id")

Page 17: JQuery

The jQuery function

$(...) = jQuery(...)

Page 18: JQuery

document.getElementsByTagName("div")

Page 19: JQuery

document.getElementsByTagName("div")

jQuery: $("div")

Page 20: JQuery

<input name="mail" type="text" />

document.getElementsByName("mail")

Page 21: JQuery

<input name="mail" type="text" />

document.getElementsByName("mail")

jQuery: $("input[name='mail']")

Page 22: JQuery

<input name="mail" type="text" />

document.getElementsByName("mail")

jQuery: $("*[name='mail']")

Page 23: JQuery

The power of Selectors

Page 24: JQuery
Page 25: JQuery

$("*[name='mail']")

Page 26: JQuery
Page 27: JQuery

$(...)

Page 28: JQuery
Page 29: JQuery
Page 30: JQuery

jQuery Object

Page 31: JQuery
Page 32: JQuery

All the magic

Page 33: JQuery
Page 34: JQuery

Attributes API

Page 35: JQuery

$("img").attr("src")

$("img").attr("src", "/new/icon.png")

Page 36: JQuery

Traversing API

Page 37: JQuery

Manipulation API

Page 38: JQuery

$("div").html()

$("div").html("<span class='red'>Hello <b>World</b></span>")

Page 39: JQuery

CSS API

Page 40: JQuery

$("div").css("color")

$("div").css("color","red")

Page 41: JQuery

Events API

Page 42: JQuery

$("p").click(fn)

$("p").click(function() { // do something});

$("p").click()

Page 43: JQuery

Effects API

Page 44: JQuery

$("p").show()

$("p").hide()

Page 45: JQuery

Ajax API

Page 46: JQuery

$("p").load( url, [data], [callback] )

$("p").load("another.html")

Page 47: JQuery
Page 48: JQuery

Chaining

Page 49: JQuery

$("a").attr("href", "foo.html").show().html("foo");

Page 50: JQuery

Ex. 1 – Mousedown

Page 51: JQuery
Page 52: JQuery
Page 53: JQuery

$(document).ready(function(){ $("a").mousedown( function() { $(this).click(function () { return false; }); goURL($(this).attr("href")); });});

Page 54: JQuery
Page 55: JQuery

$(document).ready(function(){ $("a[target='middlearea']").mousedown( function() { $(this).click(function () { return false; }); goIframeURL($(this).attr("href")); });});

Page 56: JQuery
Page 57: JQuery

$(document).ready(function(){ $("a[target!='middlearea']").mousedown( function() { $(this).click(function () { return false; }); goURL($(this).attr("href")); });});

Page 58: JQuery

Try it yourself

Page 59: JQuery
Page 60: JQuery

Demo 1

Page 61: JQuery

Ex. 2 – Marquee

Page 62: JQuery
Page 63: JQuery

$(document).ready(function(){ $.ajaxSetup({ cache: false }); setTimeout("loadInfo()", 60000); setTimeout("loadMar()", 60000);});

Page 64: JQuery

function loadInfo() { $("#infoUL").load("header.do?method=info", null, infoCallback);}function loadMar() { $("#mar").load("header.do?method=marquee", null, marCallback);}

Page 65: JQuery

function infoCallback(responseText, textStatus, XMLHttpRequest) { setTimeout("loadInfo()", 60000);}function marCallback(responseText, textStatus, XMLHttpRequest) { setTimeout("loadMar()", 60000);}

Page 66: JQuery

Demo 2

Page 67: JQuery

Ex. 3 – On Idle Action

Page 68: JQuery
Page 69: JQuery
Page 70: JQuery

include.jsp

$(document).ready(function(){ $("iframe").load(function(){ $.cookie('lastAction', new Date().getTime()); });});

Page 71: JQuery

index.jsp

$(document).ready(function(){ setTimeout("checkLastAction()", 60000);});

Page 72: JQuery

function checkLastAction() { var interval = new Date().getTime() - $.cookie('lastAction'); if (interval > (20 * 60 * 1000)) { $("iframe[name='bodyFrame']") .attr("contentWindow").location.href = $("iframe[name='bodyFrame']").attr("src");

$.cookie('lastAction', new Date().getTime()); } setTimeout("checkLastAction()", 60000);}

Page 73: JQuery

Thanks