Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

adavis

Regra css em documento java script

Recommended Posts

Como inserir um trecho no código abaixo para que o input da função pegue uma classe .error do jquery validate??

 
<script type="text/javascript">
;(function( $ ) {
 
 // Browser supports HTML5 multiple file?
 var multipleSupport = typeof $('<input/>')[0].multiple !== 'undefined',
     isIE = /msie/i.test( navigator.userAgent );
 
 $.fn.customFile = function() {
 
   return this.each(function() {
 
     var $file = $(this).addClass('customfile'), // the original file input
         $wrap = $('<div class="customfile-wrap">'),
         $input = $('<input type="text" class="customfile-filename" />'),
         // Button that will be used in non-IE browsers
         $button = $('<button type="button" class="customfile-upload">Selecionar</button>'),
         // Hack for IE
         $label = $('<label class="customfile-upload" for="'+ $file[0].id +'">Selecionar</label>');
 
     // Hide by shifting to the left so we
     // can still trigger events
     $file.css({
       position: 'absolute',
       left: '-9999px'
     });
 
     $wrap.insertAfter( $file )
       .append( $file, $input, ( isIE ? $label : $button ) );
 
     // Prevent focus
     $file.attr('tabIndex', -1);
     $button.attr('tabIndex', -1);
 
     $button.click(function () {
       $file.focus().click(); // Open dialog
     });
 
     $file.change(function() {
 
       var files = [], fileArr, filename;
 
       // If multiple is supported then extract
       // all filenames from the file array
       if ( multipleSupport ) {
         fileArr = $file[0].files;
         for ( var i = 0, len = fileArr.length; i < len; i++ ) {
           files.push( fileArr[i].name );
         }
         filename = files.join(', ');
 
       // If not supported then just take the value
       // and remove the path to just show the filename
       } else {
         filename = $file.val().split('\\').pop();
       }
 
       $input.val( filename ) // Set the value
         .attr('title', filename) // Show filename in title tootlip
         .focus(); // Regain focus
 
     });
 
     $input.on({
       blur: function() { $file.trigger('blur'); },
       keydown: function( e ) {
         if ( e.which === 13 ) { // Enter
           if ( !isIE ) { $file.trigger('click'); }
         } else if ( e.which === 8 || e.which === 46 ) { // Backspace & Del
           // On some browsers the value is read-only
           // with this trick we remove the old input and add
           // a clean clone with all the original events attached
           $file.replaceWith( $file = $file.clone( true ) );
           $file.trigger('change');
           $input.val('');
         } else if ( e.which === 9 ){ // TAB
           return;
         } else { // All other keys
           return false;
         }
       }
     });
 
   });
 
 };
 
 // Old browser fallback
 if ( !multipleSupport ) {
   $( document ).on('change', 'input.customfile', function() {
 
     var $this = $(this),
         // Create a unique ID so we
         // can attach the label to the input
         uniqId = 'customfile_'+ (new Date()).getTime(),
         $wrap = $this.parent(),
 
         // Filter empty input
         $inputs = $wrap.siblings().find('.customfile-filename')
           .filter(function(){ return !this.value }),
 
         $file = $('<input type="file" id="'+ uniqId +'" name="'+ $this.attr('name') +'"/>');
 
     // 1ms timeout so it runs after all other events
     // that modify the value have triggered
     setTimeout(function() {
       // Add a new input
       if ( $this.val() ) {
         // Check for empty fields to prevent
         // creating new inputs when changing files
         if ( !$inputs.length ) {
           $wrap.after( $file );
           $file.customFile();
         }
       // Remove and reorganize inputs
       } else {
         $inputs.parent().remove();
         // Move the input so it's always last on the list
         $wrap.appendTo( $wrap.parent() );
         $wrap.find('input').focus();
       }
     }, 1);
 
   });
 }
 
}( jQuery ));
 
$('input[type=file]').customFile();
</script>
 
 

Compartilhar este post


Link para o post
Compartilhar em outros sites

  • Conteúdo Similar

    • Por Rafael_Ferreira
      Não consigo carregar a imagem do captcha do meu formulário. Foi testado com o xampp e easyphp. Também não carregou a imagem de outros captcha. 
       
       
    • Por luiz monteiro
      Olá.
      Estou atualizando meu conhecimento com Front-End e me deparei com o seguinte problema.
      Criei um sistema para fazer o upload de imagens e alguns campos text.
      Algo bem simples para depois começar a estudar javascript para mostrar a miniatura....
      Mas quando saio do navegador Chrome ou da aba por mais de 3 minutos, ao retornar o navegador as vezes atualiza ou nem chega atualizar mas limpa os campos.
      Estou usando um Smart Motorola com Android, mas um amigo testou no iPhone e acontece a mesma coisa.
      Gostaria de saber se há como usar javascript para evitar isso?
      Agradeço desde já.

      <!DOCTYPE html>
      <html>
      <head>
          <meta charset="utf-8">
          <meta name="viewport" content="width=device-width, initial-scale=1">
          <title>Uploader</title>
      </head>
      <body>
          <form action="?" method="post" enctype="multipart/form-data">
              <br><br>
              <div>selecione a imagem 1</div>
              <input type="file" name="foto1" accept="image/*">
              <br><br>
              <input type="text" name="nome_imagem1">
              
              <br><br>
              <input type="file" name="foto2" accept="image/*">
              <br><br>
              <input type="text" name="nome_imagem2">
              
              <br><br>

              <input type="file" name="foto3" accept="image/*">
              <br><br>
              <input type="text" name="nome_imagem3">
              
              <br><br>
              <input type="submit" value="Enviar">
              <br><br>
          </form>
      <?php
      if ($_SERVER['REQUEST_METHOD'] == 'POST')
      {
          vardump ($_FILES);
      }
      ?>
      </body>
      </html>
       
       
       
    • Por belann
      Olá!
       
      Estou usando o nextjs versão 15.2.3 e criei uma navbar que quando é carregado o programa aparece com a home, mas na hora de clicar na página produtos desaparece a navbar.
      A navbar esta sendo chamada no layout.tsx estou usando typescript
      e fica dessa forma
      <div>           <Navbar/>             <main>{children}</main>             </div>  
    • Por ILR master
      Fala pessoal, tudo bem?
       
      Eu tenho o seguinte código:
       
      <script>
         $(function(){
      var jElement = $('.fixar_banner');
      $(window).scroll(function(){
          if ( $(this).scrollTop() > 120 ){
              jElement.css({
                  'position':'fixed',
                  'top':'10px'
              });
          }else{
              jElement.css({
                  'position':'relative',
                  'top':'auto'
              });
          }
      });
      });
      </script>
       
      Porém, eu quero que a div fique fixa até que outro elemento apareça na tela, tipo o rodapé da página por exemplo. É mais ou menos como a página de notícia do uol.
      https://noticias.uol.com.br/internacional/ultimas-noticias/2025/01/19/sonho-americano-brasileiros-moram-em-carro-e-buscam-comida-no-lixo-nos-eua.htm
       
      Espero ter sido claro.
       
      Obrigado :)
       
    • Por violin101
      Caros amigos, saudações.

      Estou com uma dúvida, referente cálculo de valores em tempo real.

      Tenho uma rotina, que faz o cálculo, o problema é mostrar o resultado.

      Quero mostrar o RESULTADO assim: 0,00  ou  0.00

      Abaixo posto o código.
      jQuery('input').on('keyup',function(){ //Remover ponto e trocar a virgula por ponto var m = document.getElementById("pgRest").value; while (m.indexOf(".") >= 0) { m = m.replace(".", ""); } m = m.replace(",","."); //Remover ponto e trocar a virgula por ponto var j = document.getElementById("pgDsct").value; while (j.indexOf(".") >= 0) { j = j.replace(".", ""); } j = j.replace(",","."); m = parseFloat(jQuery('#pgRest').val() != '' ? jQuery('#pgRest').val() : 0); j = parseFloat(jQuery('#pgDsct').val() != '' ? jQuery('#pgDsct').val() : 0); //Mostra o Resultado em Tempo Real jQuery('#pgTroco').val(m - j); <<=== aqui estou errando })  
       
      Grato,
       
      Cesar
       
       
×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.