18
jQue ry tips&tri cks Janko Jovanović

jQuery Tips & Tricks

  • Upload
    dzovan

  • View
    1.344

  • Download
    3

Embed Size (px)

DESCRIPTION

These slides are from CodeCamp2009 Belgrade. In my session "jQuery Tips & Tricks" I talked about jQuery basics, but focus was on creating Ajax-enabled web applications with jQuery and ASP.NET

Citation preview

Page 1: jQuery Tips & Tricks

jQuery

tips&tricks

Janko Jovanović

Page 2: jQuery Tips & Tricks

Ne volite JavaScript i

koristite update panele i Ajax

control toolkit?

Page 3: jQuery Tips & Tricks

jQuery je drugačiji• Jednostavan kod• Brzina• Cross browser kompatibilnost• Plugin-ovi• Support• Fenomenalan community

Page 4: jQuery Tips & Tricks
Page 5: jQuery Tips & Tricks

Intellisense

za Visual Studio 2008

Page 6: jQuery Tips & Tricks

Jednostavan?

Page 7: jQuery Tips & Tricks

<script type="text/javascript“ src=“jquery.js"></script>

Page 8: jQuery Tips & Tricks

$(document).ready(function(){ alert(“Brži sam od load!”);});

Load ili Ready?

Page 9: jQuery Tips & Tricks

<div><img src=“logo.png” alt=“Logo” /><a href=“#”>Link</a><p>Lorem ipsum, itd…</p><a href=“#”>Još jedan link</a>

</div>

1. Pronađi sve linkove

2. Podesi da se linkovi otvaraju u novom prozoru

<div><img src=“logo.png” alt=“Logo” /><a href=“#” target=“_blank”>Link</a><p>Lorem ipsum, itd…</p><a href=“#” target=“_blank”>Još jedan link</a>

</div>

Page 10: jQuery Tips & Tricks

Kako?

$(“a”).attr(“target”, “_blank”);

Pronađi (CSS selektor)

Uradi nešto (metode)

Selektor $(“a”) vraća jQuery objekat koji sadrži listu svih pronađenih elemenata

<a href=“#”>Link</a><a href=“#”>Još

jedan</a>

Page 11: jQuery Tips & Tricks

$(“div”).addClass(“new”) .append(“<p></p>”) .css(“color”,”#fff”) .hide(400) .click(function(){ alert(“OK!”); });

Chaining

Page 12: jQuery Tips & Tricks

$(“#container”)Vraća element sa ID-jem “container”

$(“li:first”)Vraća prvi listitem u nizu

$(“table tr:odd”)Vraća sve neparne redove u tabeli

$(“input[type=text]”)Vraća sve “TextBox” elemente

Šta

god

pože

lite

da n

ađete

Page 13: jQuery Tips & Tricks

Manipulacija.before() .after() .append()

Atributi.css() .attr() .val() .html()

Događaji.click() .focus() .toggle()

“Traversing”.find() .next() .children()

Šta

god

pože

lite

da u

radit

e

Page 14: jQuery Tips & Tricks

$(document).ready(function() { $.ajax({ type: "POST", url: "Default.aspx/GetClient", data: "{‘id’:’17’}", contentType: "application/json”; dataType: "json", success: function(msg) { // Uradi nešto sa rezultatom }, error: function(msg) {

// prikaži poruku } }); });

Ajax, pravi ajax

Page 15: jQuery Tips & Tricks

jQuery UI

Page 16: jQuery Tips & Tricks

Teorija nije zanimljiva, demo jeste

Page 17: jQuery Tips & Tricks

Pitanja(i

odgovori)

Page 18: jQuery Tips & Tricks

Janko JovanovićWeb: www.jankoatwarpspeed.comEmail: [email protected]

Twitter: @jankowarpspeed