Jump to content

Aparecer imagem de um link automaticamente


Recommended Posts

Posted (edited)

já consegui resolver

<input type="text" id="imgsrc" />
<div id="imagem">
</div>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript" language="javascript"></script>
<script>
jQuery.noConflict();
jQuery('#imgsrc').change(function(){
var img = jQuery(this).val();
jQuery('#imagem').prepend('<img src="'+img+'" />');
});
</script>
</body>
Edited by brunoais
jQuery n é uma linguagem de programação. Javascript já o é.
Posted

Bem... se esse código HTML funciona corretamente algo está bem errado....

"[Os jovens da actual geração]não lêem porque não envolve um telecomando que dê para mirar e atirar, não falam porque a trapalhice é rainha e o calão é rei" autor: thoga31

Life is a genetically transmitted disease, induced by sex, with death rate of 100%.

Posted

testado e a funcionar


<!DOCTYPE html>
<html>
 <head>
   <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
   <script>
     $(document).ready(function() {
     $('#imgsrc').change(function(event) {
       if (window.File && window.FileReader && window.FileList && window.Blob) {
         // Great success! All the File APIs are supported.
         var f = event.target.files[0];

         var reader = new FileReader();
         reader.onloadend = function() {
           $('#imagem').prepend('<img />');
           $('#imagem img').attr('src', reader.result);
         }
         reader.readAsDataURL(f);

         var description = '';
         description += '<ul>';
         description += '<li>';
         description += '<strong>'+escape(f.name)+'</strong>';
         description += ' (';
         description += f.type || 'n/a';
         description += ') - ';
         description += f.size;
         description += ' bytes';
         description += ', last modified: ';
         description += f.lastModifiedDate ? f.lastModifiedDate.toLocaleDateString() : 'n/a';
         description += '</li>';
         description += '</ul>';

         $('#imagem').append(description);
       } else {
         $('#imagem').html("cannot present image");
       }
     });
   });
   </script>
 </head>
 <body>
   <input type="file" id="imgsrc" />
   <div id="imagem">
   </div>
 </body>
</html>

sources : http://jsfiddle.net/ugPDx/ e http://www.html5rocks.com/en/tutorials/file/dndfiles/

IRC : sim, é algo que ainda existe >> #p@p

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.