Welcome to Idea R | Branding - Web Agency - Digital Strategies
Switch to the mobile layout

      Idea R - Do you have a real web strategy? Persuasion Technologies
  • HomeHome
  • About UsAbout Us
  • ContactsContacts

Blog

Take a software geek from the 80s, add a new generation graphic designer and dilute with a long time marketing strategist. Shake vigorously and you'll get the Idea R's blog.

Change language... italiano

You may be interested in

Irritated by your blog performance? Boost it using the cloud!

Irritated by your blog performance? Boost it using the cloud!

Are you using the world's fastest hosting? If you have a bad architecture, your blog won't have a great performance. Here is the ultimate solution.

How to skip the CDN during ASP.NET development

How to inject the Content Delivery Network URL in the production website without having to hardcode it.

Last published

Can engineering industry sponsor art without going off topic?

Can engineering industry sponsor art without going off topic?

How to design a page in an exhibition catalog of Biennale in Venice, for a customer who apparently has nothing to do with art.

Milano Design Week 2017, Design Districts

Ventura Lambrate and Tortona, here are the best creations that we discovered in the 2 districts of the Fuorisalone Milan Design Week 2017.

Most popular

Lazy loading and the SEO problem, solved!

Lazy loading and the SEO problem, solved!

The best SEO solution to index your dynamically loaded contents, no more compromises!

Case study: TAV Engineering, branding for B2B services

How to create a brand that keeps distance from the cold and aseptic image of the metal industry, focusing instead on the human aspect.

Editor's pick

Mental marketing secret #1: the fake compromise

Mental marketing secret #1: the fake compromise

Can mentalism influence marketing? As a marketing professional and a long term magician, I will reveal you some tricks.

How to dramatically increase social media LIKEs to your web site

Here's a free download that I created some time ago. It's a good tool for increasing engagement, but use with caution.
newsletter

Stay informed on digital strategies

RSS feed

jQuery: come lanciare e gestire gli eventi personalizzati

Published on 11/22/2012
jQuery: come lanciare e gestire gli eventi personalizzati

Avevamo già visto in un articolo precedente come gestire gli eventi JavaScript.
jQuery semplifica ma soprattutto uniforma il motore di eventi di JavaScript con 2 semplici metodi: bind() per sottoscriversi ad un evento e trigger() per lanciarlo.

Gli eventi non sono però solo una prerogativa degli oggetti standard DOM (Document Object Model), anche i vostri oggetti possono lanciare eventi, persino se non hanno nulla a che fare con il DOM.
In linea generale con jQuery ci si sottoscrive agli eventi usando le seguente forma

$(mySelector).bind('click', function(event){...});

o la forma più contratta

$(mySelector).click(function(event){...});

Come anticipato ci si può sottoscrivere anche ad eventi personalizzati, con

$(mySelector).bind('mycustomevent', function(event){...});

che a loro volta verranno lanciati dall'oggetto personalizzato con

$(mySelector).trigger('mycustomevent');

Domanda: se volessi passare delle informazioni all'event handler al momento del binding?
Risposta: si può passare qualsiasi informazione specificandola nell'istruzione bind che poi l'event handler recupererà dalla proprietà data dell'oggetto event.

// Use myCustomData to hold bind-time data
$(mySelector).bind('mycustomevent', myCustomData, function(event)
{
    ...

    // event.data contains myCustomData
    var myData = event.data;

    ...
});

Altra domanda: e se volessi passare delle informazioni all'event handler al momento del lancio dell'evento?
Risposta: si definisce semplicemente un parametro aggiuntivo nell'event handler.

// Use myParam to hold trigger-time data
$(mySelector).bind('mycustomevent', function(event, myParam){...});
...
$(mySelector).trigger('mycustomevent', 'this is the trigger-time parameter');

See also

Eventi JavaScript? Che confusione!

Vediamo di fare un po' di ordine sul sistema di eventi JavaScript e di capire quale usare a seconda della situazione.

You are the reader number 3,957.

Comments

comments powered by Disqus
Creative Commons License

Photographies, videos, graphics and texts by Idea R are licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

Previous article

Previous article

An App to see Amsterdam through Anne Frank's eyes

Next article

3 methods to detect mobile devices in ASP.NET

Next article
  • Visual Communication, Art DirectionVisual Communication, Art Direction
  • Apps, Cloud, Mobile, Software DesignApps, Cloud, Mobile, Software Design
  • Digital StrategiesDigital Strategies
  • BlogBlog
Touching finger
RSS feed
Blog

Scroll to top