[Web2.0] Jquery (sono all'inizio) SOLUZIONE

Simone Volpini simonevolpini a yahoo.it
Mer 11 Lug 2007 17:28:23 CEST


diego.unali a fastwebnet.it wrote:
> io proverei a fare una cosa del tipo
> 
> $("a").toggle(function(){
>     $("#att_1 > #test strong a").html('ON');
> },function(){
>     $("#att_1 > #test strong a").html('OFF');
> });
> 


Alla fine ho trovato la soluzione, la pubblico qui sotto nel caso possa
servire.

// Funzione che al click sul link cambia lo stato del record da
// ON a OFF e viceversa
(function() {

    jQuery.fn.change_link = function() {

        var oLink = this;

        oLink.click(function() {

            if ($(this).text() == 'OFF'){
                $(this).load("prova1.php");
            } else {
                $(this).load("prova2.php");
            }
        });
    };

})(jQuery);



$(document).ready(function() {
    $("a").change_link();
});

ed infine l'html della tabella:
<table>
<tr>
	<td>Pinco</td>
	<td>Pallino</td>
	<td>Via finta, 3</td>
	<td><strong><a>OFF</a></strong></td>
</tr>
<tr>
	<td>Mario</td>
	<td>Rossi</td>
	<td>Viale della Vittoria, 263</td>
	<td><strong><a>ON</a></strong></td>
</tr>
</table>


Simone



Maggiori informazioni sulla lista Web2.0