Ir para conteúdo
Fórum Script Brasil
  • 0

Função dinamica


paty nunes

Pergunta

Bom dia,

preciso de ajuda para refazer este codigo javascript dinamico..

vou precisar criar 56 clicks....

Codigo JavaScript

$(document).ready(function() {

            var click1ok = false;
            var click2ok = false;
            var click3ok = false;
            var click4ok = false;
            var click5ok = false;
            var click6ok = false;
            var click7ok = false;
            var click8ok = false;
            var click9ok = false;
            var click10ok = false;
            var click11ok = false;
            var click12ok = false;
            var click13ok = false;
            var click14ok = false;
            var click15ok = false;
            var click16ok = false;
            var click17ok = false;
            var click18ok = false;
            var click19ok = false;
            var click20ok = false;
            var click21ok = false;
            var click22ok = false;
            var click23ok = false;
            var click24ok = false;

            $('#contProgram1').hide();
            $('#contProgram2').hide();
            $('#contProgram3').hide();
            $('#contProgram4').hide();
            $('#contProgram5').hide();
            $('#contProgram6').hide();
            $('#contProgram7').hide();
            $('#contProgram8').hide();
            $('#contProgram9').hide();
            $('#contProgram10').hide();
            $('#contProgram11').hide();
            $('#contProgram12').hide();
            $('#contProgram13').hide();
            $('#contProgram14').hide();
            $('#contProgram15').hide();
            $('#contProgram16').hide();
            $('#contProgram17').hide();
            $('#contProgram18').hide();
            $('#contProgram19').hide();
            $('#contProgram20').hide();
            $('#contProgram21').hide();
            $('#contProgram22').hide();
            $('#contProgram23').hide();
            $('#contProgram24').hide();

            $('#click1').click(function() {
                if (click1ok == false) {
                    click1ok = true;
                    $('#ctl00_main_ImageExpand1').attr({ src: "~/Imagens/expand_-.png", alt: "Expand -" });
                    $('#contProgram1').slideDown('slow');

                    click2ok = false;
                    $('#ctl00_main_ImageExpand2').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram2').slideUp('slow');
                    click3ok = false;
                    $('#ctl00_main_ImageExpand3').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram3').slideUp('slow');
                    click4ok = false;
                    $('#ctl00_main_ImageExpand4').attr({ src: ".~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram4').slideUp('slow');
                    click5ok = false;
                    $('#ctl00_main_ImageExpand5').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram5').slideUp('slow');
                    click6ok = false;
                    $('#ctl00_main_ImageExpand6').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram6').slideUp('slow');
                    click7ok = false;
                    $('#ctl00_main_ImageExpand7').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram7').slideUp('slow');
                    click8ok = false;
                    $('#ctl00_main_ImageExpand8').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram8').slideUp('slow');
                    click9ok = false;
                    $('#ctl00_main_ImageExpand9').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram9').slideUp('slow');
                    click10ok = false;
                    $('#ctl00_main_ImageExpand10').attr({ src: "~/Imagens/expand_-.png", alt: "Expand -" });
                    $('#contProgram10').slideUp('slow');
                    click11ok = false;
                    $('#ctl00_main_ImageExpand11').attr({ src: "~/Imagens/expand_-.png", alt: "Expand -" });
                    $('#contProgram11').slideUp('slow');
                    click12ok = false;
                    $('#ctl00_main_ImageExpand12').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram12').slideUp('slow');
                    click13ok = false;
                    $('#ctl00_main_ImageExpand13').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram13').slideUp('slow');
                    click14ok = false;
                    $('#ctl00_main_ImageExpand14').attr({ src: ".~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram14').slideUp('slow');
                    click15ok = false;
                    $('#ctl00_main_ImageExpand15').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram15').slideUp('slow');
                    click16ok = false;
                    $('#ctl00_main_ImageExpand16').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram16').slideUp('slow');
                    click17ok = false;
                    $('#ctl00_main_ImageExpand17').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram17').slideUp('slow');
                    click18ok = false;
                    $('#ctl00_main_ImageExpand18').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram18').slideUp('slow');
                    click19ok = false;
                    $('#ctl00_main_ImageExpand19').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram19').slideUp('slow');
                    click20ok = false;
                    $('#ctl00_main_ImageExpand20').attr({ src: "~/Imagens/expand_-.png", alt: "Expand -" });
                    $('#contProgram20').slideUp('slow');
                    click21ok = false;
                    $('#ctl00_main_ImageExpand21').attr({ src: "~/Imagens/expand_-.png", alt: "Expand -" });
                    $('#contProgram21').slideUp('slow');
                    click22ok = false;
                    $('#ctl00_main_ImageExpand22').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram22').slideUp('slow');
                    click23ok = false;
                    $('#ctl00_main_ImageExpand23').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram23').slideUp('slow');
                    click24ok = false;
                    $('#ctl00_main_ImageExpand24').attr({ src: ".~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram24').slideUp('slow');
                } else if (click1ok == true) {
                    click1ok = false;
                    $('#ctl00_main_ImageExpand1').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram1').slideUp('slow');
                }
            });

            $('#click2').click(function() {
                if (click2ok == false) {
                    click2ok = true;
                    $('#ctl00_main_ImageExpand2').attr({ src: "~/Imagens/expand_-.png", alt: "Expand -" });
                    $('#contProgram2').slideDown('slow');

                    click1ok = false;
                    $('#ctl00_main_ImageExpand1').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram1').slideUp('slow');
                    click3ok = false;
                    $('#ctl00_main_ImageExpand3').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram3').slideUp('slow');
                    click4ok = false;
                    $('#ctl00_main_ImageExpand4').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram4').slideUp('slow');
                    click5ok = false;
                    $('#ctl00_main_ImageExpand5').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram5').slideUp('slow');
                    click6ok = false;
                    $('#ctl00_main_ImageExpand6').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram6').slideUp('slow');
                    click7ok = false;
                    $('#ctl00_main_ImageExpand7').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram7').slideUp('slow');
                    click8ok = false;
                    $('#ctl00_main_ImageExpand8').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram8').slideUp('slow');
                    click9ok = false;
                    $('#ctl00_main_ImageExpand9').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram9').slideUp('slow');
                    click10ok = false;
                    $('#ctl00_main_ImageExpand10').attr({ src: "~/Imagens/expand_-.png", alt: "Expand -" });
                    $('#contProgram10').slideUp('slow');
                    click11ok = false;
                    $('#ctl00_main_ImageExpand11').attr({ src: "~/Imagens/expand_-.png", alt: "Expand -" });
                    $('#contProgram11').slideUp('slow');
                    click12ok = false;
                    $('#ctl00_main_ImageExpand12').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram12').slideUp('slow');
                    click13ok = false;
                    $('#ctl00_main_ImageExpand13').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram13').slideUp('slow');
                    click14ok = false;
                    $('#ctl00_main_ImageExpand14').attr({ src: ".~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram14').slideUp('slow');
                    click15ok = false;
                    $('#ctl00_main_ImageExpand15').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram15').slideUp('slow');
                    click16ok = false;
                    $('#ctl00_main_ImageExpand16').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram16').slideUp('slow');
                    click17ok = false;
                    $('#ctl00_main_ImageExpand17').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram17').slideUp('slow');
                    click18ok = false;
                    $('#ctl00_main_ImageExpand18').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram18').slideUp('slow');
                    click19ok = false;
                    $('#ctl00_main_ImageExpand19').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram19').slideUp('slow');
                    click20ok = false;
                    $('#ctl00_main_ImageExpand20').attr({ src: "~/Imagens/expand_-.png", alt: "Expand -" });
                    $('#contProgram20').slideUp('slow');
                    click21ok = false;
                    $('#ctl00_main_ImageExpand21').attr({ src: "~/Imagens/expand_-.png", alt: "Expand -" });
                    $('#contProgram21').slideUp('slow');
                    click22ok = false;
                    $('#ctl00_main_ImageExpand22').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram22').slideUp('slow');
                    click23ok = false;
                    $('#ctl00_main_ImageExpand23').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram23').slideUp('slow');
                    click24ok = false;
                    $('#ctl00_main_ImageExpand24').attr({ src: ".~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram24').slideUp('slow');
                } else if (click2ok == true) {
                    click2ok = false;
                    $('#ctl00_main_ImageExpand2').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram2').slideUp('slow');
                }
            });

            $('#click3').click(function() {
                if (click3ok == false) {
                    click3ok = true;
                    $('#ctl00_main_ImageExpand3').attr({ src: "~/Imagens/expand_-.png", alt: "Expand -" });
                    $('#contProgram3').slideDown('slow');

                    click1ok = false;
                    $('#ctl00_main_ImageExpand1').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram1').slideUp('slow');
                    click2ok = false;
                    $('#ctl00_main_ImageExpand2').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram2').slideUp('slow');
                    click4ok = false;
                    $('#ctl00_main_ImageExpand4').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram4').slideUp('slow');
                    click5ok = false;
                    $('#ctl00_main_ImageExpand5').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram5').slideUp('slow');
                    click6ok = false;
                    $('#ctl00_main_ImageExpand6').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram6').slideUp('slow');
                    click7ok = false;
                    $('#ctl00_main_ImageExpand7').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram7').slideUp('slow');
                    click8ok = false;
                    $('#ctl00_main_ImageExpand8').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram8').slideUp('slow');
                    click9ok = false;
                    $('#ctl00_main_ImageExpand9').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram9').slideUp('slow');
                    click10ok = false;
                    $('#ctl00_main_ImageExpand10').attr({ src: "~/Imagens/expand_-.png", alt: "Expand -" });
                    $('#contProgram10').slideUp('slow');
                    click11ok = false;
                    $('#ctl00_main_ImageExpand11').attr({ src: "~/Imagens/expand_-.png", alt: "Expand -" });
                    $('#contProgram11').slideUp('slow');
                    click12ok = false;
                    $('#ctl00_main_ImageExpand12').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram12').slideUp('slow');
                    click13ok = false;
                    $('#ctl00_main_ImageExpand13').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram13').slideUp('slow');
                    click14ok = false;
                    $('#ctl00_main_ImageExpand14').attr({ src: ".~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram14').slideUp('slow');
                    click15ok = false;
                    $('#ctl00_main_ImageExpand15').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram15').slideUp('slow');
                    click16ok = false;
                    $('#ctl00_main_ImageExpand16').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram16').slideUp('slow');
                    click17ok = false;
                    $('#ctl00_main_ImageExpand17').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram17').slideUp('slow');
                    click18ok = false;
                    $('#ctl00_main_ImageExpand18').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram18').slideUp('slow');
                    click19ok = false;
                    $('#ctl00_main_ImageExpand19').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram19').slideUp('slow');
                    click20ok = false;
                    $('#ctl00_main_ImageExpand20').attr({ src: "~/Imagens/expand_-.png", alt: "Expand -" });
                    $('#contProgram20').slideUp('slow');
                    click21ok = false;
                    $('#ctl00_main_ImageExpand21').attr({ src: "~/Imagens/expand_-.png", alt: "Expand -" });
                    $('#contProgram21').slideUp('slow');
                    click22ok = false;
                    $('#ctl00_main_ImageExpand22').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram22').slideUp('slow');
                    click23ok = false;
                    $('#ctl00_main_ImageExpand23').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram23').slideUp('slow');
                    click24ok = false;
                    $('#ctl00_main_ImageExpand24').attr({ src: ".~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram24').slideUp('slow');
                } else if (click3ok == true) {
                    click3ok = false;
                    $('#ctl00_main_ImageExpand3').attr({ src: "~/Imagens/expand_+.png", alt: "Expand +" });
                    $('#contProgram3').slideUp('slow');
                }
            });
Codigo Aspx
<div id="click1" class="Expand">
                    <div class="ExpandImage">
                        <asp:Image ID="ImageExpand1" runat="server" ImageUrl="~/Imagens/expand_+.png" />
                    </div>
                    <div class="ExpandText">
                        <h4>
                            <asp:Label ID="Labe46" runat="server" Text="Quando o certificado A3 é inutilizado?" />
                        </h4>
                    </div>
                </div>
                <div id="contProgram1" class="Conteudo">
                    <p>
                        <asp:Label ID="Label2" runat="server" Text="O Certificado Digital A3 será inutilizado em quaisquer das seguintes situações:após
                        três tentativas incorretas de digitação do PIN, seguido de três tentativas incorretas
                        de digitação do PUK, esquecimento do PIN e do PUK, perda do cartão inteligente ou
                        token, formatação do cartão inteligente ou token, apagamento da chave privada ou
                        do certificado digital. Nesses casos, será necessária a aquisição de um novo Certificado
                        Digital." />
                    </p>
                </div>
            </div>

Se alguém puder me ajudar ficarei muito agradecida

Link para o comentário
Compartilhar em outros sites

3 respostass a esta questão

Posts Recomendados

  • 0

i aew paty nunes, tenta algo mais ou menos assim:

<script type='text/javascript'>
function actionClicks( aClicks , iClick )
{
    if ( aClicks[iClick] == false )
    {
        for ( var i = 0; i < aClicks.length; i++ )
        {
            if ( i == iClick )
            {
                aClicks[i] = true;
                $( '#ctl00_main_ImageExpand' + ( iClick + 1 ) ).attr( { src : "~/Imagens/expand_-.png", alt: "Expand -" } );
                $( '#contProgram' + ( iClick + 1 ) ).slideDown( 'slow' );
            }
            else
            {
                aClicks[i] = false;
                $( '#ctl00_main_ImageExpand' + ( i + 1 ) ).attr( { src : "~/Imagens/expand_+.png" , alt : "Expand +" } );
                $( '#contProgram'  + ( i + 1 ) ).slideUp( 'slow' );
            }
        }        
    } 
    else if ( aClicks[iClick] == true )
    {
        aClicks[iClick] = false;
        $( '#ctl00_main_ImageExpand' + ( iClick + 1 ) ).attr( { src: "~/Imagens/expand_+.png" , alt : "Expand +" } );
        $( '#contProgram' + ( iClick + 1 ) ).slideUp( 'slow' );
    }
}

$( function(){
    var clickok = new Array( 24 );
    for ( var i = 0; i < clickok.length; i++ )
    {
        $( '#contProgram' + ( i + 1 ) ).hide();
        clickok[i] = false;
    }
    for ( i = 0; i < 3; i++ )
    {
        $( '#click' + ( i + 1 ) ).click( function(){
            actionClicks( clickok , i )
        } );
    }
}
</script>

qualquer coisa posta ai, abraço!

Editado por Romerito
Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,3k
    • Posts
      652,3k
×
×
  • Criar Novo...