简体   繁体   中英

Html and javascript: how to switch download link to button

I have a export to excel link on my page like:

<a download="queryResults.csv" href="#" onclick="return ExcellentExport.csv(this, 'datatable');">Export to CSV</a>

I would like to present it as a button, I tried something like:

<button download="queryResults.csv" href="#" onclick="return ExcellentExport.csv(this, 'datatable');">Export to CSV</button>

Hoe should I get it to work? Thanks.

 <a download="queryResults.csv"  
   onclick="return ExcellentExport.csv(this, 'datatable');" href="#"> 
   <button>Export to CSV</button>
 </a>

The button element has no href attribute. Instead you have to provide a type attribute, which has to be type="button" . See the specs here: HTML button tag

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM