Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

HTML <a> download 属性

❮ HTML <a> 标签

示例

点击链接时下载文件(而不是导航到文件)

<a href="/images/myw3schoolsimage.jpg" download>
亲自试一试 »

下面还有更多“亲自试一试”示例。


定义和用法

The download 属性指定当用户点击超链接时,目标(在 href 属性中指定的的文件)将被下载。

The download 属性的可选值为下载后文件的新名称。没有对允许值的限制,浏览器会自动检测正确的文件扩展名并将其添加到文件中(.img、.pdf、.txt、.html 等)。

如果省略该值,则使用原始文件名。


浏览器支持

表中的数字指定第一个完全支持该属性的浏览器版本。

属性
download 14.0* 18.0 20.0* 10.1 15.0

* Chrome 65+ 和 Firefox 仅支持相同来源的下载链接。


语法

<a download="filename">

属性值

描述
filename 可选。指定下载文件的新的文件名

更多示例

示例

为 download 属性指定一个值,该值将是下载文件的新的文件名(“w3logo.jpg”而不是“myw3schoolsimage.jpg”)

<a href="/images/myw3schoolsimage.jpg" download="w3logo">
亲自试一试 »

❮ HTML <a> 标签
×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.