Upload file

Trở về

  • 3,266

Đôi khi trong một số trường hợp ta dùng liên kết để upload file thay vì dùng mặc định từ input type=”file”

<input type="file"> được thay thế bằng liên kết

Sử dụng một liên kết để thay thế cho <input type="file">

Html viết:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Học Web Chuẩn</title>
<script src="https://code.jquery.com/jquery-latest.js"></script>
<script>
$(function(){
    var upFile = $(":input[type=file]");
    upFile.hide();
    $("a.file").click(function(){
        upFile.click();
    });
});
</script>
</head>
<body>
<form>
<a class="file" href='javascript:;'>Upload file</a>
<input type="file"/>
</form>
</body>
</html>

Hiển thị trình duyệt:

Download file để thực hành

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.