본문 바로가기
Web

jQuery Form Plugin - Example

by leo21c 2013. 6. 5.
SMALL

출처: http://jquery.malsup.com/form/progress.html
jQuery Form Plugin을 이용해서 파일을 올리는 샘플 소스이다.

<!doctype html>
<head>
<title>File Upload Progress Demo #1</title>
<style>
body { padding: 30px }
form { display: block; margin: 20px auto; background: #eee; border-radius: 10px; 
   padding: 15px }
.progress { position:relative; width:400px; border: 1px solid #ddd; padding: 1px; 
    border-radius: 3px; }
.bar { background-color: #B4F5B4; width:0%; height:20px; border-radius: 3px; }
.percent { position:absolute; display:inline-block; top:3px; left:48%; }
</style>
</head>
<body>
  <h1>File Upload Progress Demo #1</h1>
  <code><input type="file" name="myfile"></code>
  <form action="file-echo2.php" method="post" enctype="multipart/form-data">
    <input type="file" name="myfile"><br>
    <input type="submit" value="Upload File to Server">
  </form>

  <div class="progress">
    <div class="bar"></div >
    <div class="percent">0%</div>
  </div>

  <div id="status"></div>
</body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<script>
(function() {
  var bar = $('.bar');
  var percent = $('.percent');
  var status = $('#status');

  $('form').ajaxForm({
    beforeSend: function() {
      status.empty();
      var percentVal = '0%';
      bar.width(percentVal)
      percent.html(percentVal);
    },
    uploadProgress: function(event, position, total, percentComplete) {
      var percentVal = percentComplete + '%';
      bar.width(percentVal)
      percent.html(percentVal);
    },
    success: function() {
      var percentVal = '100%';
      bar.width(percentVal)
      percent.html(percentVal);
    },
    complete: function(xhr) {
      status.html(xhr.responseText);
    }
  });
})();
</script>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-850242-2";
urchinTracker();
</script>


LIST

'Web' 카테고리의 다른 글

Dovecot POP3 설정 후에도 Outlook에서 로그인이 안되는 경우  (0) 2013.10.17
jQuery Form Plugin - Option  (0) 2013.06.05
jQuery Form Plugin - API  (0) 2013.06.05
CSS3 Transform  (0) 2012.07.19
Loading a DLL from memory  (30) 2008.02.14