Warning, world wide web development

Gli Script Javascript indispensabili e tra i più utili per i webmaster


I 10 scripts più utili nello sviluppo di applicazioni javascript e ajax sono i seguenti: 10) addEvent() function


function addEvent(element, eventType, fn, useCapture) {

if (element.addEventListener) {

element.addEventListener(eventType, fn, useCapture);

return true;

}

else if (element.attachEvent) {

var r = element.attachEvent('on' + eventType, fn);

return r;

}

else {

element['on' + eventType] = fn;

}

}
9) addLoadEvent() by Simon Willison function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { oldonload(); func(); } } } 8) getElementsByClass Non è un metodo originale del DOM come uno possa pensare comunque, abbiamo getElementById, getElementsByName(), getElementsByTagName, cosa succede attraverso getElementsByClass??? Ecco la risposta: getElementsByClass by Dustin Diaz function getElementsByClass(searchClass,node,tag) { var classElements = new Array(); if ( node == null ) node = document; if ( tag == null ) tag = '*'; var els = node.getElementsByTagName(tag); var elsLen = els.length; var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)'); for (i = 0, j = 0; i < elsLen; i++) { if ( pattern.test(els[i].className) ) { classElements[j] = els[i]; j++; } } return classElements; } Semplice aggiungere un nome della classe all'inizio della funzione e il 2nd e il 3rd argomento sono opzionali. 7) toggle() function toggle(obj) { var el = document.getElementById(obj); if ( el.style.display != 'none' ) { el.style.display = 'none'; } else { el.style.display = ''; } } 6) inserAfter (public domain) function insertAfter(parent, node, referenceNode) { parent.insertBefore(node, referenceNode.nextSibling); } 5) inArray() Array.prototype.inArray = function (value) { var i; for (i=0; i < this.length; i++) { if (this[i] === value) { return true; } } return false; }; 4,3,2) setCookie(),getCookie(),deleteCookie() function getCookie( name ) { var start = document.cookie.indexOf( name + "=" ); var len = start + name.length + 1; if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) { return null; } if ( start == -1 ) return null; var end = document.cookie.indexOf( ';', len ); if ( end == -1 ) end = document.cookie.length; return unescape( document.cookie.substring( len, end ) ); } function setCookie( name, value, expires, path, domain, secure ) { var today = new Date(); today.setTime( today.getTime() ); if ( expires ) { expires = expires * 1000 * 60 * 60 * 24; } var expires_date = new Date( today.getTime() + (expires) ); document.cookie = name+'='+escape( value ) + ( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString() ( ( path ) ? ';path=' + path : '' ) + ( ( domain ) ? ';domain=' + domain : '' ) + ( ( secure ) ? ';secure' : '' ); } function deleteCookie( name, path, domain ) { if ( getCookie( name ) ) document.cookie = name + '=' + ( ( path ) ? ';path=' + path : '') + ( ( domain ) ? ';domain=' + domain : '' ) + ';expires=Thu, 01-Jan-1970 00:00:01 GMT'; } 1) La vostra fantasia.

Tags: , , , ,

Articoli correlati

  • Aggiungi ai favoriti… questo script
  • gresearch
  • Script Javascript per integrare Technotizie facilmente nel vostro sito.
  • Firebug Extension
  • Come inserire un bottone digg interno a blogspot
  • Seguici Tramite Feed Rss Se ti è piaciuto questo articolo, seguici


    Scrivi un commento

    Close
    E-mail It