Ir para conteúdo

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 ILR master
      Pessoal, pergunta bem simples. Abaixo tenho o seguinte código:
       
      <script>
      function alerta()
      {
        if (window.confirm("Você realmente quer sair?")) {
          window.open("sair.html");
      }
      }
      </script>
       
      Funciona perfeitamente, só que está abrindo em outra janela e quero que abra na mesma janela.
       
      Alguém pode me ajudar?
    • Por Giovanird
      Olá a todos!
      Tenho uma pagina que possui uma DIV onde coloquei uma pagina PHP.
      Uso a função setInterval para atualizar a pagina inclusa dentro da DIV.
      O problema é que ao acessar o site , a DIV só me mostra a pagina inclusa somente quando completo o primeiro minuto.
      Preciso que a pagina inclusa já inicie carregada
       
      Meu código JavaScript e a DIV com a pagina PHP
       
      <script> function atualiza(){ var url = 'direita.php'; $.get(url, function(dataReturn) { $('#direita').html(dataReturn); }); } setInterval("atualiza()",60000); </script> <div> <span id="direita"></span> </div>  
    • Por Thiago Duarte
      Oi, gostaria de arrastar imagem e ao soltar formar bloco html, meu bloco de html ficaria com nome, content-1.html, content-2.html, etc
       
      Alguem pode me ajudar?
    • Por juliosonic
      Boa noite..
      Estou desenvolvendo um site de https://www.maithunatantra.com.br/ e estou com um duvida sobre o menu de navegação da versão mobile.
      O menu que tem o dropdown "Terapeutas" e "Terapias" quando clico em cima ele expande como deve ser, mas quando clico denovo para recolher os submenus
      nao acontece nada.. segue o trecho do codigo do menu..
      <div class="collapse navbar-collapse" id="navbarsExample09">             <ul class="navbar-nav ml-auto">               <li class="nav-item  active"><a class="nav-link" href="index.html">Home</a></li>               <li class="nav-item  active"><a class="nav-link" href="about-us.html">Quem Somos</a></li>               <li class="nav-item dropdown1">                     <a class="nav-link dropdown-toggle" data-toggle="dropdown1" href="#">Terapeutas</a>                     <ul class="dropdown-menu">                         <li><a class="dropdown-item" href="terapeuta-julio-cezar.html">Julio Cezar</a></li>                         <li><a class="dropdown-item" href="terapeuta-pamela-priscila.html">Pamela Priscila</a></li>                     </ul>                                    </li>               <li class="nav-item dropdown">                     <a class="nav-link dropdown-toggle" data-toggle="dropdown1" href="#">Terapias</a>                     <ul class="dropdown-menu" aria-labelledby="dropdown01">                         <li><a class="dropdown-item" href="o-que-e-reiki.html">O que é Reiki</a></li>                         <li><a class="dropdown-item" href="beneficios-reiki.html">Benefícios do Reiki</a></li>                         <li><a class="dropdown-item" href="principios-reiki.html">Princípios do Reiki</a></li>                         <li><a class="dropdown-item" href="animais-reiki.html">Reiki em Animais</a></li>                         <li><a class="dropdown-item" href="animais-reiki.html">Estudos Sobre Reiki</a></li>                         <li><a class="dropdown-item" href="terapia-massagem-tantrica.html">Terapia Tântrica</a></li>                     </ul>               </li>               <li class="nav-item  active"><a class="nav-link" href="blog.html">Blog</a></li>                <li class="nav-item"><a class="nav-link" href="contato.html">Contato</a></li>             </ul>         </div>  
      Massagem Tantrica em Curitiba
      Tantra Curitiba
      Massagem Tântrica
      Tantra
      Julio Darshan

      Obrigado
      Att
      Julio Cezar
       
       
       
    • Por belann
      Olá!
       
      Estou fazendo o upload de arquivos com fetch dessa forma
      fetch(url, {
              method: 'POST',
              headers: {'Content-Type': 'multipart/form-data',},
              body: formData 
          }).catch((error) => (console.log("Problemas com o Upload"), error));
       
      estou usando input type=file
      e criando uma const formData = new FormData(); 
      mas não faz e não dá nenhum erro.
      estou fazendo o upload com a url="http://localhost/dashboard/dados".
×

Informação importante

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